簡體   English   中英

在具有多個或條件的彈性搜索上匹配查詢

[英]match query on elastic search with multiple or conditions

我有三個字段statustypesearch 我想要的是搜索包含status等於NEWstatus等於IN PROGRESStype等於abctype等於xyzsearch contains(partial match)。

我的電話如下所示-

{
 "query": {
  "bool" : {
      "must" : [{
                "match": {
                "status": {
                    "query": "abc",
                    }
                }
                }, {
                    "match": {
                    "type": {
                        "query": "NEW",
                        }
                    }
                },{
                    "query_string": {
                        "query": "*abc*",    /* for partial search */
                        "fields": ["title", "name"]
                    }
                }]
        }
    }
}

嵌套您的boolqueries。 我認為您缺少的是:

"bool": { "should": [ 
   { "match": { "status": "abc" } }, 
   { "match": { "status": "xyz" } } 
]}

這是一個查詢,該查詢必須與應子句之一匹配,因為僅應給出應子句。

編輯來解釋差異:

{
   "query": {
      "bool": {
         "must": [
            {
               "bool": {
                  "should": [
                     {
                        "match": {
                           "status": "abc"
                        }
                     },
                     {
                        "match": {
                           "status": "xyz"
                        }
                     }
                  ]
               }
            },
            {
               "terms": {
                  "type": [
                     "NEW",
                     "IN_PROGRESS"
                  ]
               }
            },
            {
               "query_string": {
                  "query": "*abc*",
                  "fields": [
                     "title",
                     "name"
                  ]
               }
            }
         ]
      }
   }
}

因此,您在頂部有一個boolquery。 3個內部查詢中的每個查詢都必須為真。

  1. 第一個是嵌套的boolquery,如果狀態匹配abc或xyz,則為true。
  2. 如果類型完全匹配NEW或IN_PROGRESS,則第二個為true-請注意此處的區別。 根據您的分析儀,第一個也會匹配ABC或aBc或可能的“ abc XYZ”。 您可能需要兩者都使用。
  3. 第三是你以前擁有的。

暫無
暫無

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

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