Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
<img src="//i.stack.imgur.com/RUiNP.png" height="16" width="18" alt="" class="sponsor tag img">elasticsearch Elasticsearch查询:通过比较值列表选择文档(golang)_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Go - Fatal编程技术网 elasticsearch Elasticsearch查询:通过比较值列表选择文档(golang),elasticsearch,go,elasticsearch,Go" /> elasticsearch Elasticsearch查询:通过比较值列表选择文档(golang),elasticsearch,go,elasticsearch,Go" />

elasticsearch Elasticsearch查询:通过比较值列表选择文档(golang)

elasticsearch Elasticsearch查询:通过比较值列表选择文档(golang),elasticsearch,go,elasticsearch,Go,我有一种在ElasticSearch中索引的文档类型,其结构简化如下: { id: "54" properties: ["nice", "green", "small", "dry"] } 现在,我想选择该索引中的所有文档,在属性字段中不包含给定值的列表 类似于:SELECT*从属性不包含[“红色”、“大”、“恐怖”的索引中选择] 如何在elasticsearch上实现该功能? (我有人知道如何在Golang上实现这样的查询,我会更好:-) 谢谢 您可以使用子句bool从索引中

我有一种在ElasticSearch中索引的文档类型,其结构简化如下:

{
    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运行良好