Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merging two queries with a common part #1647

Open
oren0e opened this issue Jun 4, 2023 · 0 comments
Open

Merging two queries with a common part #1647

oren0e opened this issue Jun 4, 2023 · 0 comments

Comments

@oren0e
Copy link

oren0e commented Jun 4, 2023

Hi,
Currently if I do something like this:

from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search
from elasticsearch_dsl.query import Q

client = Elasticsearch("http://<ADDRESS>:9200", size=10000, from_=0, index="test")
q1 = Q({"range": {"updated_at": {"gte": "2023-05-30"}}})
q2 = Q({"range": {"updated_at": {"gte": "2023-05-30", "lte": "now"}}})

s = Search(using=client, index="test").query(q1).query(q2)

print(s.to_dict())

I will get something like the following:

{'query': {'bool': {'must': [{'range': {'updated_at': {'gte': '2023-05-30'}}}, {'range': {'updated_at': {'gte': '2023-05-30', 'lte': 'now'}}}]}}}

I would expect that the resulting query will merge the two common gte parts to have something like this (I don't mind that this will continue to live inside a bool-must block):

{'query': {'bool': {'must': [{'range': {'updated_at': {'gte': '2023-05-30', 'lte': 'now'}}}]}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants