es should查詢--一個字段多個值的查詢情況 相當於mysql中的in的操作,OR 和AND用法

在工作中,ES,遇到了一個字段多個值的查詢情況。可以用should 和 terms。其中 minimum_should_match 表示最小匹配項數量.

可以參考這篇文章:elasticsearch查詢api:terms query

下面是嘗試:在kibana中運行

terms:

{
  "query": {
    "terms": {
      "subopt": [
        "lianmaiStu",
        "end_lianmaiStu"
      ],
      "minimum_should_match": 1
    }
  }
}

但是發現報錯了:

{
  "error": {
    "root_cause": [
      {
        "type": "parsing_exception",
        "reason": "[terms] query does not support [minimum_should_match]",
        "line": 8,
        "col": 31
      }
    ],
    "type": "parsing_exception",
    "reason": "[terms] query does not support [minimum_should_match]",
    "line": 8,
    "col": 31
  },
  "status": 400
}

查找一番後,發現。ES不支持terms 中加minimum_should_match ,具體查看:terms query does not support minimum_match in Elasticsearch 2.3.3

 

2、should: 是可以使用的滿足條件。

GET zhiboevent_test_201908/_search
{
  "query": {
    "bool": {
      "must": [
        {"match": { "opt": "useropt" }},
        {"match": {"lid": "113446603_79"}}
      ],
      "should": [
        {
          "match": {
            "subopt": "lianmaiStu"
          }
        },
        {
          "match": {
            "subopt": "end_lianmaiStu"
          }
        }
      ],
      "minimum_should_match":1
    }
  }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章