Skip to content

Commit

Permalink
visitor: support nested fields for wildcard queries
Browse files Browse the repository at this point in the history
* INSPIR-3614
  • Loading branch information
MJedr committed Jun 16, 2020
1 parent 1795ade commit 7887fa9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion inspire_query_parser/visitors/elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ def handle_value_wildcard(self, node, fieldnames=None):
fieldnames=fieldnames,
analyze_wildcard=True
)
return query
return wrap_query_in_nested_if_field_is_nested(query, fieldnames, self.NESTED_FIELDS)

def handle_author_query(self, node, fieldnames=None):
bai_fieldnames = self._generate_fieldnames_if_bai_query(
Expand Down
21 changes: 21 additions & 0 deletions tests/test_elastic_search_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3429,3 +3429,24 @@ def test_range_date_queries_are_nested():

generated_es_query = _parse_query(query_str)
assert generated_es_query == expected_es_query


def test_queries_with_wildcard_support_nested_fields():
query_str = 'publication_info.cnum:*'
expected_es_query = {
"nested": {
"path": "publication_info",
"query": {
"query_string": {
"query": "*",
"fields": [
"publication_info.cnum"
],
"analyze_wildcard": True
}
}
}
}

generated_es_query = _parse_query(query_str)
assert generated_es_query == expected_es_query

0 comments on commit 7887fa9

Please sign in to comment.