我有一个带有以下映射的Elasticsearch索引“库”:
{
"mappings": {
"book": {
"properties": {
"title": { "type": "text", "index": "not_analyzed" },
"author": { "type": "text", "index": "not_analyzed" },
"price": { "type": "integer" },
}
}
}
现在我要进行查询以查找作者数等于3的所有文档(书)。即,我要进行查询以使其匹配
curl -XGET "http://localhost:9200/library/_search?pretty=true" -d '{
"query": {
"match": {
Number of values of term "author" = 3.
}
}
}'
有什么方法可以在不添加额外术语的情况下进行此类查询?
[我知道可以在搜索结果中找到一个词的所有可能值的聚合,但是无法根据上述标准转换该聚合。]
最佳答案
无法找到一种方法来准确地获得每个作者拥有3个文档。
汇总将为您提供所有可能的值。但是,它也会向您显示doc_count
-在这里我们可以找到自己的方式:
{
"size": 0,
"aggregations": {
"authors": {
"terms": {
"field": "author",
"min_doc_count": 3,
"size": 5
}
}
}
}
min_doc_count -仅过滤至少包含3个文档的存储桶。
大小-仅会为您提供前5个文档(请记住,默认情况下,存储桶按'doc_count'升序排序)。
现在,您可以调整
size
以获得具有3个文档的确切作者。
关于elasticsearch - Elasticsearch查询以查找术语数量等于指定数量的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47634484/