elasticSearch Alternatively use a keyword field instead.


es 查詢的時候報錯了

    
{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [parent_row_id] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "dc_org_newpearl_function_tree",
        "node": "1C7XnVeiRF-vCZAR2jdpnQ",
        "reason": {
          "type": "illegal_argument_exception",
          "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [parent_row_id] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
        }
      }
    ],
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [parent_row_id] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.",
      "caused_by": {
        "type": "illegal_argument_exception",
        "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [parent_row_id] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
      }
    }
  },
  "status": 400
}        
參考  https://www.cnblogs.com/Neeo/articles/10771885.html

其實也就是說明 字段的類型不是keyword 類型,因此不支持 某些查詢方式:比如排序,聚合 等

而且 字段條件查詢 也是 查詢不到內容或者想要的結果的

比如 這個字段 :

"parent_row_id" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },



那么要查詢 就需要額外帶上 keyword 才可以 
GET /dc_org_newpearl_function_tree/_search
{
  "query": {
    "term": {
      "parent_row_id.keyword": {
                        "value": "",
                        "boost": 1.0
                    }
    }
  }
}

或者 
GET /dc_org_newpearl_function_tree/_search
{
  "sort": [
    {
      "parent_row_id.keyword": {
        "order": "asc"
      }
    }
  ]
}

或者聚合查詢 帶上 keyword
    "aggregations": {
        "group_parent_row_id": {
            "terms": {
                "field": "parent_row_ids.keyword",
                "size": 100,
                "min_doc_count": 1,
                "shard_min_doc_count": 0,
                "show_term_doc_count_error": false,
                "order": [{
                    "_count": "desc"
                }, {
                    "_key": "asc"
                }]
            }
        }
    }
 

或者解決辦法就是 刪除索引重建了,將 對應字段 類型改為keyword

.startObject("parent_row_ids").field("type", "keyword").endObject()

 

es 查詢的時候報錯了

	
{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [parent_row_id] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "dc_org_newpearl_function_tree",
        "node": "1C7XnVeiRF-vCZAR2jdpnQ",
        "reason": {
          "type": "illegal_argument_exception",
          "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [parent_row_id] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
        }
      }
    ],
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [parent_row_id] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.",
      "caused_by": {
        "type": "illegal_argument_exception",
        "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [parent_row_id] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
      }
    }
  },
  "status": 400
}		

參考  https://www.cnblogs.com/Neeo/articles/10771885.html

其實也就是說明 字段的類型不是keyword 類型,因此不支持 某些查詢方式:比如排序,聚合 等

而且 字段條件查詢 也是 查詢不到內容或者想要的結果的

比如 這個字段 :

"parent_row_id" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },



那么要查詢 就需要額外帶上 keyword 才可以 
GET /dc_org_newpearl_function_tree/_search
{
  "query": {
    "term": {
      "parent_row_id.keyword": {
						"value": "",
						"boost": 1.0
					}
    }
  }
}

或者 
GET /dc_org_newpearl_function_tree/_search
{
  "sort": [
    {
      "parent_row_id.keyword": {
        "order": "asc"
      }
    }
  ]
}

或者聚合查詢 帶上 keyword
	"aggregations": {
		"group_parent_row_id": {
			"terms": {
				"field": "parent_row_ids.keyword",
				"size": 100,
				"min_doc_count": 1,
				"shard_min_doc_count": 0,
				"show_term_doc_count_error": false,
				"order": [{
					"_count": "desc"
				}, {
					"_key": "asc"
				}]
			}
		}
	}

 

或者解決辦法就是 刪除索引重建了,將 對應字段 類型改為keyword

.startObject("parent_row_ids").field("type", "keyword").endObject()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM