zoukankan      html  css  js  c++  java
  • 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()
  • 相关阅读:
    新年放大招:Github 私库免费了!
    阿里启动新项目:Nacos,比 Eureka 更强!
    运行 Spring Boot 应用的 3 种方式
    过了所有技术面,却倒在 HR 一个问题上。。
    hdu 5428 The Factor(数学)
    poj 2385 Apple Catching(dp)
    poj 2229 Sumsets(dp 或 数学)
    poj 1759 Garland (二分搜索之其他)
    poj 3662 Telephone Lines(好题!!!二分搜索+dijkstra)
    poj 3669 Meteor Shower(bfs)
  • 原文地址:https://www.cnblogs.com/roak/p/14359718.html
Copyright © 2011-2022 走看看