elasticSearch Alternatively use a keyword field instead

elasticSearch Alternatively use a keyword field instead.| Id | Title | DateAdded | SourceUrl | PostType | Body | BlogId | Description | DateUpdated | IsMarkdown | EntryName | CreatedTime | IsActive | AutoDesc | AccessPermission |

| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------| -------------|
| 14359718| elasticSearch Alternatively use a keyword field instead.| 2021-02-01T23:27:00| | BlogPost|

复制代码

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()
| 648658| | 2024-04-29T20:51:00| false| | 2021-02-01T23:27:20.627| true| es 查询的时候报错了 { "error": { "root_cause": [ { "type": "illegal_argument_exception", "reason": "Fielddata is disabled on text fields by default. Set field| Anonymous|
posted @   RalphLauren  阅读(22)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示