gpt4 book ai didi

elasticsearch - 在 Elasticsearch 中,为什么会收到错误消息 "Fielddata is disabled on text fields by default"

转载 作者:行者123 更新时间:2023-12-02 22:48:10 24 4
gpt4 key购买 nike

我正在尝试编写一个查询来返回唯一的城市。我的代码是:

GET /files/_doc/_search
{
"size":"0",
"aggs" : {
"uniq_cities" : {
"terms" : { "field" : "cities" }

}
}
}

我有如下错误消息:

Fielddata is disabled on text fields by default. Set fielddata=true on [cities] 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.



当我跑
GET /files/_doc/_mapping

我得到:
"cities" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}

基于以上,看来我已经有了一个关键字字段。如何修复错误消息?

最佳答案

错误提示“默认情况下在文本字段上禁用字段数据”,因为您尝试在文本字段上应用聚合 cities .它还有一个子字段 keyword其数据类型为 keyword .因此,在 cities.keyword 上应用聚合。字段如下:

GET /files/_doc/_search
{
"size":"0",
"aggs" : {
"uniq_cities" : {
"terms" : { "field" : "cities.keyword" }

}
}
}

关于elasticsearch - 在 Elasticsearch 中,为什么会收到错误消息 "Fielddata is disabled on text fields by default",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54955251/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com