ElasticSearch multi_match, if the field has an applicable filter, otherwise donโ€™t worry about it?

So, we got an elasticsearch instance, but the task requires a โ€œcombo searchโ€ (one search field with checkboxes for typesa specific index)

This is good, I just apply this kind of search to my index (for brevity: / posts):

{
    "query": {
        "multi_match": {
            "query": querystring, 
            "type":"cross_fields",
            "fields":["title","name"] 
            }
        } 
    }
}

As you can guess about the need to use multi_match here, the schemes for each of these types are different in one way or another. And this is my task right now.

, , , , active 0 1.
, , .

, . active 1, . .

" , , 1, "? ?

+4
1

, , 1,

, :

{
  "query": {
    "filtered": {
      "filter": {
        "bool": {
          "should": [
            {
              "bool": {
                "must": [
                  {
                    "exists": {
                      "field": "active"
                    }
                  },
                  {
                    "term": {
                      "active": 1
                    }
                  }
                ]
              }
            },
            {
              "missing": {
                "field": "active"
              }
            }
          ]
        }
      }
    }
  }
}

:

{
  "query": {
    "filtered": {
      "query": {
        "multi_match": {
          "query": "whatever",
          "type": "cross_fields",
          "fields": [
            "title",
            "name"
          ]
        }
      },
      "filter": {
        "bool": {
          "should": [
            {
              "bool": {
                "must": [
                  {
                    "exists": {
                      "field": "active"
                    }
                  },
                  {
                    "term": {
                      "active": 1
                    }
                  }
                ]
              }
            },
            {
              "missing": {
                "field": "active"
              }
            }
          ]
        }
      }
    }
  }
}
+8

Source: https://habr.com/ru/post/1613574/


All Articles