gpt4 book ai didi

elasticsearch - 如何从Elasticsearch直接获取按字段过滤的选项?

转载 作者:行者123 更新时间:2023-12-03 01:36:03 26 4
gpt4 key购买 nike

我想根据我在Elasticsearch中建立索引的数据填充一个过滤字段。如何获取这些数据?例如,我在索引“test”和类型“doc”中的文档可能是

{"id":1, "tag":"foo",  "name":"foothing"}
{"id":2, "tag":"bar", "name":"barthing"}
{"id":3, "tag":"foo", "name":"something"}
{"id":4, "tag":"quux", "name":"quuxthing"}

我正在寻找类似 GET /test/doc/_magic?q=tag的东西,该东西将从我的数据中返回 [foo,bar,quux]。我不知道这叫什么,甚至不可能。我不想将所有索引条目都存储到内存中并以编程方式执行此操作,因此索引中有数百万个文档,其中包含大约一百个不同的标签。

ES有可能吗?

最佳答案

是的,这是可能的,这被称为 terms aggregation

您可以这样做:

GET /test/doc/_search
{
"size": 0,
"aggs" : {
"tags" : {
"terms" : {
"field" : "tag.keyword",
"size": 100
}
}
}
}

请注意,根据 tag字段的基数,您可以增加/减少 size设置(默认为10)。

关于elasticsearch - 如何从Elasticsearch直接获取按字段过滤的选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52607087/

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