elasticsearch查询所有数组元素

时间:2016-12-26 15:53:01

标签: elasticsearch

如何在以下查询中搜索包含所有指定标记的文档?我尝试了minimum_should_match和"执行":"和",但我的查询中都没有支持它们。

GET products/fashion/_search
{
  "query": { 
    "constant_score": {
      "filter" : {
        "bool" : {
          "must" : [
            {"terms" : {
              "tags" : ["gucci", "dresses"]
            }},
            {"range" : {
              "price.value" : {
                "gte" : 100,
                "lt" : 1000
              }
            }}
          ]
        }
      }
    }
  },
  "sort": { "date": { "order": "desc" }}
}

======更新

我找到了构建查询的方法。任务是在elasticsearch中重现以下mongodb查询:

{
  "tags": {
    "$all":["gucci","dresses"]
  },
  "price.value":{"$gte":100,"$lte":1000}
}

这是我的弹性搜索查询

GET products/fashion/_search
{
  "query": { 
    "bool" : {
      "filter" : [
        {"term" : {
          "tags" : "gucci"
        }},
        {"term" : {
          "tags" : "dresses"
        }},
        {"range" : {
          "price.value" : {
            "gte" : 100,
            "lt" : 1000
          }
        }}
      ]
    }
  }
}

1 个答案:

答案 0 :(得分:0)

您是否为索引定义了映射?默认情况下,Elasticsearch将分析字符串字段。如果您想查找上面的确切术语,则需要在映射中将它们指定为not_analyzed

https://www.elastic.co/guide/en/elasticsearch/guide/current/_finding_exact_values.html#_term_filter_with_text