-
Notifications
You must be signed in to change notification settings - Fork 76
Add support for nested bool queries #165
Comments
What is it you want to add support for? multi_match? |
No, the usage of the boolean must in the fashion above. In terms of Python code I had to do this: query_components = []
if what_or_who != 'all':
query_components.append({
'multi_match': {
'query': what_or_who,
'fields': ['%s.lowercase' % field for field in ES_WHAT_FIELDS]
}})
if where != 'all':
query_components.append({
'multi_match': {
'query': where,
'fields': ['%s.lowercase' % field for field in ES_WHERE_FIELDS]
}})
if query_components:
search = search.query_raw({
'bool': {
'must': query_components
}
}) where I expected to be able to do something like this: queries = []
# Base query
if what_or_who != 'all':
queries.append(Q(should=True, **{'%s.lowercase__match' % field: what_or_who.lower() for field in ES_WHAT_FIELDS}))
if where != 'all':
queries.append(Q(should=True, **{'%s.lowercase__match' % field: where.lower() for field in ES_WHERE_FIELDS})
s = s.query(must=True, *queries) Am I missing something? Is there a way to do this already? |
I'm puzzled. ElasticUtils doesn't support multi-match, so neither of your code fragments will produce a multi-match. What does the second code fragment produce? Can you do |
The second code fragment doesn't work:
Effectively the query builder flattens the query structure down. As it is, the equivalent of the following SQL snippet requires the use of a raw query: WHERE (a = 1 OR b = 2) AND (c = 3 OR d = 4 OR e=5) |
With regards to the multi_match, that's not important since I'm just using as a shorter way of doing a bool with a should, although I realise I should specify it to use bool and not dis |
shoulds, musts and must_nots get flattened, so you can't build a nested set of them. That's the way I implemented it. To date, no one has mentioned needing this and I haven't seen a compelling use case to warrant the added complexity. I'll fix the title of your issue and let this sit and see if it gathers momentum. |
Okay, cool. I may fork and play around with getting this to work myself. If I do manage it, I'll let you know :-) |
I haven't heard anything about this since August. @robhudson did have a use case for it, but otherwise it seems no one is interested. This requires some non-trivial rewriting of things, so I'm going to push it off until post 0.10. |
I have a use case for it, but OTOH contemplating just switching away from EU in favor of writing raw JSON - we're doing quite complex queries anyway. |
It is pretty easy to do using query_raw but it also feels like something
|
In order to execute the following query, query_raw needs to be used:
I think this could be resolved by allowing Q instances to be created that refer to nested Q instances
The text was updated successfully, but these errors were encountered: