我有一种在 ElasticSearch 中索引的文档,其简化结构如下:
{
id: "54"
properties: ["nice", "green", "small", "dry"]
}
现在我想选择该索引中的所有文档,这些文档不在 properties
字段中包含给定值的列表。
类似于:SELECT * FROM index WHERE properties NOT CONTAINS ["red", "big", "scary"]
我如何在 elasticsearch 上实现它? (而且我有人知道如何在 Golang 上实现这样的查询,我会做得更好:-))
谢谢!
最佳答案
您可以使用子句 bool
匹配索引中的那些文档。它看起来像这样:
{
"bool": {
"must_not": [
{ "term": { "properties": "red" }},
{ "term": { "properties": "big" }},
{ "term": { "properties": "scary" }}
]
}
}
查询可能是这样的:
{
"filtered": {
"query": {
"match": { "id": "54" }
},
"filter":{
"bool": {
"must_not": [
{ "term": { "properties": "red" }},
{ "term": { "properties": "big" }},
{ "term": { "properties": "scary" }}
]
}
}
}
}
有关更多信息,您可以查看此链接:Filtered query
关于 Elasticsearch 查询 : Select documents by comparing lists of values (golang),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52991389/