0

I have a query

GET index/_search

{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "key1": "value"
          }
        },
        {
          "wildcard": {
            "key2": "*match*"
          }
        }
      ]
    }
  }
}

I want to make the same call with elasticsearch_dsl package I tried with

s = Search(index=index).query({
    "bool": {
      "should": [
        {
          "match": {
            "key1": "value"
          }
        },
        {
          "wildcard": {
            "key2": "*match*"
          }
        }
      ]
    }
  })
s.using(self.client).scan()

But the results are not same, am I missing something here

Is there a way to represent my query with elasticsearch_dsl tried this, no results

s = Search(index=index).query('wildcard', key2='*match*').query('match', key1=value)
s.using(self.client).scan()
Logic
  • 2,230
  • 2
  • 24
  • 41

2 Answers2

0

it seems to me that you forgot the stars in the query.

s = Search(index=index).query('wildcard', key='*match*').query('match', key=value)
glenacota
  • 2,314
  • 1
  • 11
  • 18
0

This query worked for me

s = Search(index=index).query('match', key1=value)
                       .query('wildcard', key2='*match*')
                       .source(fields)

also, if key has _ like key_1 elastic search behaves differently and query matches results even which do not match your query. So try to choose your key which do not have underscores.

Logic
  • 2,230
  • 2
  • 24
  • 41