【问题标题】:Elasticsearch multiple where and orwhere queryElasticsearch 多个 where 和 orwhere 查询
【发布时间】:2017-06-14 17:31:35
【问题描述】:

我需要一个 elasticsearch 查询,但它必须包含多个这样的 where 和 orwhere 子句;

SELECT * FROM pictures WHERE ((width = 400 AND height = 300) OR (width = 800 AND height = 600)) AND status = 1 AND deleted = 0

谢谢。

【问题讨论】:

标签: elasticsearch where


【解决方案1】:

使用这个查询

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "status": 1
          }
        },
        {
          "match": {
            "deleted": 0
          }
        }
       ],
       "should": [
          {
            "bool": {
              "must": [
                {
                  "match": {
                    "width": "400"
                  }
                },
                {
                  "match": {
                    "height": "300"
                  }
                }
              ]
            }
          },
          {
            "bool": {
              "must": [
                {
                  "match": {
                    "width": "800"
                  }
                },
                {
                  "match": {
                    "height": "600"
                  }
                }
              ]
            }
          }
        ]
    }
  }
}

【讨论】:

    猜你喜欢
    • 2015-01-19
    • 2021-02-11
    • 1970-01-01
    • 2020-01-01
    • 1970-01-01
    • 2017-01-03
    • 2015-11-19
    • 2021-11-06
    • 1970-01-01
    相关资源
    最近更新 更多