1

I wanted to simulate SQL's IN so I used terms filter, but terms does not support wild cards like adding astrisck in "*egypt*".

so how can i achieve the following query?

PS: i am using elastica

{
  "query": {
    "bool": {
      "should": [
        {
          "terms": {
            "country_name": [
              "*egypt*",
              "*italy*"
            ]
          }
        }
      ]
    }
  },
  "sort": [
    {
      "rank": {
        "order": "desc"
      }
    }
  ]
}
Hatem Said
  • 333
  • 1
  • 13

1 Answers1

2

terms query does not support wildcards. You can use match or wildcard query instead. If your problem is multiple values to filter you can combine queries inside should, so it will look like this

{
  "query": {
    "bool": {
      "should": [
        {
          "wildcard": {
            "country_name": "*egypt*"
          }
        },
        {
            "wildcard": {
                "country_name": "*italy*"
            }
        }
      ]
    }
  },
  "sort": [
    {
      "rank": {
        "order": "desc"
      }
    }
  ]
}
Ruben Vardanyan
  • 1,298
  • 9
  • 19