Hi @abdon - firstly, thanks SO MUCH for taking the time to help me!
I'm very excited to see that there is even this possibility (to query the original field). However, I tried to use that in the wildcard search and still go the same results.
As background, I'm not using any custom analyzers, and the name field is just marked as text in my mapping. Also, I'm on Elasticsearch 6.7.
Here are the mappings (expressed in a Python dict):
'properties': {
'company_id': {'type': 'integer'},
'id': {'type': 'integer'},
'name': {'type': 'text'},
'mls': {'type': 'text'},
'buyer': {'type': 'text'},
'seller': {'type': 'text'},
'agents': {
'type': 'nested',
'properties': {
'id': {'type': 'integer'},
'email': {'type': 'text'},
'first_name': {'type': 'text'},
'last_name': {'type': 'text'},
'name': {'type': 'text'}
}
}
}
I've included the entire query in both examples below, just for completion purposes, but of course only the wildcard name field portion is relevant.
Query (uses {'wildcard': {'name.keyword': '*zaxsnzfugwbb street*'}):
{'query': {'bool': {'filter': [{'match': {'company_id': 1532}}, {'bool': {'should': [{'wildcard': {'name.keyword': '*zaxsnzfugwbb street*'}}, {'match_phrase': {'name': 'zaxsnzfugwbb street'}}, {'wildcard': {'mls': '*zaxsnzfugwbb street*'}}, {'match_phrase': {'mls': 'zaxsnzfugwbb street'}}, {'wildcard': {'buyer': '*zaxsnzfugwbb street*'}}, {'match_phrase': {'buyer': 'zaxsnzfugwbb street'}}, {'wildcard': {'seller': '*zaxsnzfugwbb street*'}}, {'match_phrase': {'seller': 'zaxsnzfugwbb street'}}, {'nested': {'path': 'agents', 'query': {'bool': {'should': [{'bool': {'filter': [{'wildcard': {'agents.first_name': 'zaxsnzfugwbb*'}}, {'wildcard': {'agents.last_name': '*street'}}]}}, {'bool': {'filter': [{'wildcard': {'agents.first_name': 'zaxsnzfugwbb*'}}, {'wildcard': {'agents.last_name': 'street*'}}]}}, {'bool': {'filter': [{'wildcard': {'agents.first_name': 'zaxsnzfugwbb*'}}, {'match_phrase': {'agents.last_name': 'street'}}]}}, {'bool': {'filter': [{'match_phrase': {'agents.first_name': 'zaxsnzfugwbb'}}, {'wildcard': {'agents.last_name': 'street*'}}]}}, {'bool': {'filter': [{'match_phrase': {'agents.first_name': 'zaxsnzfugwbb'}}, {'wildcard': {'agents.last_name': '*street'}}]}}, {'bool': {'filter': [{'match_phrase': {'agents.first_name': 'zaxsnzfugwbb'}}, {'match_phrase': {'agents.last_name': 'street'}}]}}]}}}}]}}]}}}
Results:
{'_shards': {'failed': 0, 'skipped': 0, 'successful': 1, 'total': 1},
'hits': {'hits': [{'_id': '76602400',
'_index': 'tx-general',
'_routing': '1532',
'_score': 0.0,
'_source': {'agents': [{'email': 'clzfvygaigl@gmail.com',
'first_name': 'Agnebc',
'id': 37451,
'last_name': 'Wudtfmjy'},
{'email': 'lkfbtywhilmmqiygizf@gmail.com',
'first_name': 'Vqbmmb',
'id': 39463,
'last_name': 'Hpoiwiyt'}],
'buyer': 'Vqfslk Fwdfxzzw',
'company_id': 1532,
'id': 76602400,
'mls': 'RX-88972457/Adhilyabzbjq',
'name': '0615 Zaxsnzfugwbb Street, Obgnqjua, KI 22304',
'seller': 'Plczti Witdmgck'},
'_type': 'tx'}],
'max_score': 0.0,
'total': 1},
'timed_out': False,
'took': 12}
Query (uses {'wildcard': {'name.keyword': '*xsnzfugwbb stre*'}):
{'query': {'bool': {'filter': [{'match': {'company_id': 1532}}, {'bool': {'should': [{'wildcard': {'name.keyword': '*xsnzfugwbb stre*'}}, {'match_phrase': {'name': 'xsnzfugwbb stre'}}, {'wildcard': {'mls': '*xsnzfugwbb stre*'}}, {'match_phrase': {'mls': 'xsnzfugwbb stre'}}, {'wildcard': {'buyer': '*xsnzfugwbb stre*'}}, {'match_phrase': {'buyer': 'xsnzfugwbb stre'}}, {'wildcard': {'seller': '*xsnzfugwbb stre*'}}, {'match_phrase': {'seller': 'xsnzfugwbb stre'}}, {'nested': {'path': 'agents', 'query': {'bool': {'should': [{'bool': {'filter': [{'wildcard': {'agents.first_name': 'xsnzfugwbb*'}}, {'wildcard': {'agents.last_name': '*stre'}}]}}, {'bool': {'filter': [{'wildcard': {'agents.first_name': 'xsnzfugwbb*'}}, {'wildcard': {'agents.last_name': 'stre*'}}]}}, {'bool': {'filter': [{'wildcard': {'agents.first_name': 'xsnzfugwbb*'}}, {'match_phrase': {'agents.last_name': 'stre'}}]}}, {'bool': {'filter': [{'match_phrase': {'agents.first_name': 'xsnzfugwbb'}}, {'wildcard': {'agents.last_name': 'stre*'}}]}}, {'bool': {'filter': [{'match_phrase': {'agents.first_name': 'xsnzfugwbb'}}, {'wildcard': {'agents.last_name': '*stre'}}]}}, {'bool': {'filter': [{'match_phrase': {'agents.first_name': 'xsnzfugwbb'}}, {'match_phrase': {'agents.last_name': 'stre'}}]}}]}}}}]}}]}}}
Results:
{'_shards': {'failed': 0, 'skipped': 0, 'successful': 1, 'total': 1},
'hits': {'hits': [], 'max_score': None, 'total': 0},
'timed_out': False,
'took': 54}
The first example uses the whole Zaxsnzfugwbb and Street words.
The second example just removes the first 2 letters from Zaxsnzfugwbb and the last 2 letters from Street to simulate that scenario I described.