'Querying multiple fields in Elasticsearch

I am trying to search across multiple fields with a wildcard character.

Example document fields: Boolean type field, isAllowed: true Text type field, name:John

I want to query all the documents that have isAllowed is set to true and all names start with J.

I have tried combining the two queries but it won’t compare boolean vs text.



Solution 1:[1]

You can use a filter to look for just the is_allowed true and the wildcard in a "must" clause. It will return who is allowed and who starts with "J".

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "is_allowed": {
              "value": true
            }
          }
        },
        {
          "wildcard": {
            "name": {
              "value": "j*"
            }
          }
        }
      ]
    }
  }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 andrecoelho.rabbitbr