我有一种类型的文档在ElasticSearch中建立了索引,其简化结构如下:
{
id: "54"
properties: ["nice", "green", "small", "dry"]
}
现在,我想选择此索引中的所有文档,这些文档不在properties
字段中包含给定值的列表。
类似SELECT * FROM index WHERE properties NOT CONTAINS ["red", "big", "scary"]
如何在elasticsearch上实现它? (而且有人知道我该如何在Golang上实现这样的查询,我会变得更好:-))
谢谢!
答案 0 :(得分:1)
您可以使用子句const arr = [
'a',
'b',
'c',
'd',
];
const final = [{
value: 'All',
checked: false,
},
...arr.map(x => ({
value: x,
checked: false,
})),
];
console.log(final);
从索引中匹配那些文档。看起来像这样:
bool
查询可能是这样的:
{
"bool": {
"must_not": [
{ "term": { "properties": "red" }},
{ "term": { "properties": "big" }},
{ "term": { "properties": "scary" }}
]
}
}
有关更多信息,您可以检查以下链接:Filtered query