Reputation:
Currently i use below wildcard search for my service,
{
"query": {
"bool": {
"must": [
{
"wildcard": {
"PRODUCT_DESCRIPTION": "\*collaboration\*services\*shiriyara\*"
}
}
]
}
}
}
This returns me expected result. But i am looking for alternative ways to achieve this without using wildcard query, as wildcard takes more time.
I tried "query_string" on a "standard" analyzed field. But this returns result if whole word matches.
"query_string": {
"default_field": "PRODUCT_DESCRIPTION",
"default_operator": "AND",
"query": "collaboration services shiriyara"
}
If the string is "collab services shiriyara", it won't give any result, whereas wildcard gives.
Let me know, if anybody has thoughts. Index time changes also fine with me.
Upvotes: 1
Views: 3128
Reputation: 21
I know this is an old question but in case anyone comes across it again: in Elasticsearch 7.9 a new wildcard field type optimised for quickly finding patterns inside string values has been introduced.
Upvotes: 1
Reputation: 1691
You could break up your wildcards as follows, which would work for the example you have given:
GET my_index/_search
{
"query": {
"bool": {
"must": [
{"wildcard": {"PRODUCT_DESCRIPTION": "collab*"}},
{"wildcard": {"PRODUCT_DESCRIPTION": "serv*"}},
{"wildcard": {"PRODUCT_DESCRIPTION": "shiri*"}}
]
}
}
}
Alternatively, you could look at using ngrams at index time, which would allow matching of character sequences within a word.
Upvotes: 1