Home > Back-end >  ElasticSearch-dsl intervals query
ElasticSearch-dsl intervals query

Time:12-15

I am using this library to make elastic search queries. It says that it supports intervals query but I can not find a good example that could help me in making my query.

My query is as follows:

GET index/_search
{
  "from": 0,
  "query": {
    "bool": {
      "must": [
        {
          "intervals": {
            "search_field": {
              "all_of": {
                "intervals": [
                  {
                    "match": {
                      "query": "search_term",
                      "max_gaps": 1
                    }
                  }
                ]
              }
            }
          }
        }
      ]
    }
  },
  "size": 50
}


I am trying to make dsl query something like this

Q(
   "bool",
    must=[
          Q("intervals", search_field=search_term, max_gaps=1)
    ]
 )

can someone guide me how to make the proper query or share an example. Thanks

CodePudding user response:

Could try something like this:

s = s.query(
    Q('bool', must=[
        Q('intervals', search_field={
            'all_of': {
                'intervals': [
                    Q('match', query='search_term', max_gaps=1)
                ]
            }
        })
    ])
)

CodePudding user response:

after many tries, it finally worked with this @Adelina thanks for putting me in the right direction!


s = s.query(
    Q('bool', must=[
        Q('intervals', search_field={
            'all_of': {
                'intervals': [
                    {'match': {'query': 'search_term', 'max_gaps': =1}}
                ]
            }
        })
    ])
)


  • Related