Elasticsearch 查询 : Select documents by comparing lists of values (golang)

标签 elasticsearch go

我有一种在 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/

相关文章:

elasticsearch - Elasticsearch ,最有效的 bool 映射过滤器,即选择所有true/false

elasticsearch - 无需嵌入索引即可在两个实体之间进行休眠搜索

elasticsearch - 在Logstash中为sql_last_value使用表的ID?

go - 无法在 Go 应用程序的另一个包中使用函数

go - 如何确认来自 Go 客户端的 gRPC 流量是 TLS 加密的

zlib压缩数据时的内存分配?

elasticsearch - 使用Spring使用JSON中的文档填充ElasticSearch索引

elasticsearch - Elasticsearch嵌套过滤器查询

arrays - 并行处理数组 : any risk of to much threads?

profiling - 有 Go 分析器吗?