elasticsearch Elasticsearch查询:通过比较值列表选择文档(golang)
我有一种在ElasticSearch中索引的文档类型,其结构简化如下:elasticsearch Elasticsearch查询:通过比较值列表选择文档(golang),elasticsearch,go,elasticsearch,Go,我有一种在ElasticSearch中索引的文档类型,其结构简化如下: { id: "54" properties: ["nice", "green", "small", "dry"] } 现在,我想选择该索引中的所有文档,在属性字段中不包含给定值的列表 类似于:SELECT*从属性不包含[“红色”、“大”、“恐怖”的索引中选择] 如何在elasticsearch上实现该功能? (我有人知道如何在Golang上实现这样的查询,我会更好:-) 谢谢 您可以使用子句bool从索引中
{
id: "54"
properties: ["nice", "green", "small", "dry"]
}
现在,我想选择该索引中的所有文档,在属性
字段中不包含给定值的列表
类似于:SELECT*从属性不包含[“红色”、“大”、“恐怖”的索引中选择]
如何在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" }}
]
}
}
}
}
查询可以如下所示:
{
"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" }}
]
}
}
}
}
有关更多信息,请查看此链接:golang library github.com/olivere/elastic运行良好