elasticsearch - Elasticsearch Query:通过比较值列表来选择文档(golang)
问题描述
我有一种在 ElasticSearch 中被索引的文档,其简化结构如下:
{
id: "54"
properties: ["nice", "green", "small", "dry"]
}
现在我想选择这个索引中的所有文档,它不包含properties
字段中给定值的列表。
就像是:SELECT * FROM index WHERE properties NOT CONTAINS ["red", "big", "scary"]
我如何在弹性搜索上实现它?(而且我有人知道如何在 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" }}
]
}
}
}
}
有关更多信息,您可以查看此链接:过滤查询
推荐阅读
- algorithm - 什么是弹性、鲁棒性和抗性算法?
- html - 为什么我的图标没有显示在我的网页上,我该如何做悬停效果?
- jestjs - Jest 无法测试指挥官帮助功能
- python - anaconda 环境中 pymeep-parallel 的包冲突
- angular - 如何通过 Angular 8 中的 id 获取元素来更改类并更改 div 的样式
- javascript - 恢复文件上传
- python - 如何有条件地删除熊猫中的行
- java - 如何将 RESTService 从我的核心应用程序导入到 JBPMSuite
- sql - 在oracle中如何从用户表的电子邮件列中检索具有@gmail扩展邮件的用户
- java - 违反清洁编码原则?