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()
  • 相关阅读:
    风口之下,猪都能飞。当今中国股市牛市,真可谓“错过等七年”。 给你一个回顾历史的机会,已知一支股票连续n天的价格走势,以长度为n的整数数组表示,数组中第i个元素(prices[i])代表该股票第i天的股价。 假设你一开始没有股票,但有至多两次买入1股而后卖出1股的机会,并且买入前一定要先保证手上没有股票。若两次交易机会都放弃,收益为0。 设计算法,计算你能获得的最大收益。 输入数值范围:2<=n<
    世界上有10种人,一种懂二进制,一种不懂。那么你知道两个int32整数m和n的二进制表达,有多少个位(bit)不同么?
    图——克鲁斯算法——构建最小生成树(采用邻接矩阵的方式存储)
    [liu yanling]黑盒测试用例设计方法
    [Stephen]Export from Excel to ALM
    [liu yanling]测试小结
    [liu yanling]测试用例作用
    [liu yanling]测试流程
    [liu yanling]软件测试技巧
    [liu yanling]软件测试用例的基本要素包括哪些?
  • 原文地址:https://www.cnblogs.com/roak/p/14359718.html
Copyright © 2011-2022 走看看