Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
<img src="//i.stack.imgur.com/RUiNP.png" height="16" width="18" alt="" class="sponsor tag img">elasticsearch 默认情况下,文本字段中禁用ElasticSearch 5.1 Fielddata[错误:尝试在字段中使用聚合]_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Mapping_Aggregation - Fatal编程技术网 elasticsearch 默认情况下,文本字段中禁用ElasticSearch 5.1 Fielddata[错误:尝试在字段中使用聚合],elasticsearch,mapping,aggregation,elasticsearch,Mapping,Aggregation" /> elasticsearch 默认情况下,文本字段中禁用ElasticSearch 5.1 Fielddata[错误:尝试在字段中使用聚合],elasticsearch,mapping,aggregation,elasticsearch,Mapping,Aggregation" />

elasticsearch 默认情况下,文本字段中禁用ElasticSearch 5.1 Fielddata[错误:尝试在字段中使用聚合]

elasticsearch 默认情况下,文本字段中禁用ElasticSearch 5.1 Fielddata[错误:尝试在字段中使用聚合],elasticsearch,mapping,aggregation,elasticsearch,Mapping,Aggregation,在我的映射中有这个字段 "answer": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, 我尝试执行这个聚合 "aggs": { "answer": { "terms": { "field": "answe

在我的映射中有这个字段

"answer": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
我尝试执行这个聚合

"aggs": {
"answer": {
  "terms": {
    "field": "answer"
  }
},
但是我得到了这个错误

"type": "illegal_argument_exception",
      "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [answer] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."

我必须更改映射还是使用了错误的聚合?(刚刚从2.x更新到5.1)

您需要在
关键字
子字段上进行聚合,如下所示:

"aggs": {
"answer": {
  "terms": {
    "field": "answer.keyword"
  }
},

这就行了。

除了@Val的答案之外,您还可以在映射过程中将
字段数据设置为true:

"answer": {
        "type": "text",
        "fielddata": true, <-- add this line
        "fields": {
          "keyword": {
            "type": "keyword",                
            "ignore_above": 256
          }
        }
      },
“答案”:{
“类型”:“文本”,

“fielddata”:是的,在聚合中,只需添加关键字即可回答。这对我很有效。对于文本字段,我们需要添加关键字。
“字段”:“answer.keyword”

我不确定是否接受任何
fielddata
设置,就像
text
类型一样。根据例外情况(
Set fielddata=true on[answer]
),我认为问题出在提供的映射中的
答案
。这是因为他在
答案
上聚合,但他最好在
答案.关键字
上聚合,因为他有那个字段。