diff --git a/inspire_query_parser/visitors/elastic_search_visitor.py b/inspire_query_parser/visitors/elastic_search_visitor.py index 4a6aac0..05d01ee 100644 --- a/inspire_query_parser/visitors/elastic_search_visitor.py +++ b/inspire_query_parser/visitors/elastic_search_visitor.py @@ -664,10 +664,15 @@ def visit_nested_keyword_op(self, node): # TODO Cannot be completed as of yet. 'successor', with_operator_and=False ) + self_citation = generate_match_query( + "control_number", + recid, + with_operator_and=False + ) return { 'bool': { 'must': [citing_records_query, records_with_collection_literature_query], - 'must_not': [superseded_records_query] + 'must_not': [superseded_records_query, self_citation] } } diff --git a/tests/test_elastic_search_visitor.py b/tests/test_elastic_search_visitor.py index 56ab401..6af73eb 100644 --- a/tests/test_elastic_search_visitor.py +++ b/tests/test_elastic_search_visitor.py @@ -2305,6 +2305,11 @@ def test_nested_refersto_recid_nested_keyword_query(): 'match': { 'related_records.relation': 'successor' } + }, + { + 'match': { + 'control_number': '123456' + } } ] }