簡體   English   中英

Elasticsearch 2.x-新的布爾查詢

[英]Elasticsearch 2.x - new bool query

升級到Elasticsearch 2.x后,以下查詢出現問題:

{   "query": {
    "filtered": {
      "filter": {
        "bool": {
          "should": [
            {
              "bool": {
                "must": [
                  {
                    "terms": {
                      "_type": [
                        "xxx",
                        "yyy"
                      ]
                    }
                  },
                  {
                    "exists": {
                      "field": "aaa"
                    }
                  },
                  {
                    "exists": {
                      "field": "bbb"
                    }
                  },
                  {
                    "exists": {
                      "field": "ccc"
                    }
                  }
                ]
              }
            },
            {
              "bool": {
                "must": [
                  {
                    "term": {
                      "_type": "eee"
                    }
                  },
                  {
                    "term": {
                      "f": 0
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    }   } }

基本上,我不知道如何用Elasticsearch 2.x中的新查詢DSL規則替換“應該”過濾器中的“必須”。

提前致謝。

您可以簡單地刪除已filtered/filter部分並按如下方式修改查詢:

{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "must": [
              {
                "terms": {
                  "_type": [
                    "xxx",
                    "yyy"
                  ]
                }
              },
              {
                "exists": {
                  "field": "aaa"
                }
              },
              {
                "exists": {
                  "field": "bbb"
                }
              },
              {
                "exists": {
                  "field": "ccc"
                }
              }
            ]
          }
        },
        {
          "bool": {
            "must": [
              {
                "term": {
                  "_type": "eee"
                }
              },
              {
                "term": {
                  "f": 0
                }
              }
            ]
          }
        }
      ]
    }
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM