which is the Best option for Wildcard Search with multimatch and why ?
Wildcard with multi-match
{
"query": {
"multi_match": {
"query": "*king*",
"fields": [
"text",
"title"
]
}
}
}
Alternatively to multi_match we could use a query_string query with wildcards.
"query": {
"query_string": {
"query": "*king*",
"fields": [ "text", "title" ]
}
}
Other Options are :
multimatch
query requires match
queries as its internal queries. and a match
query doesn't support wildcards. Depending how we want to combine scores from multiple fields, we may use dis_max query 112, that can accept wildcard queries as well.
In Elasticsearch, we generally use multi_match query that uses best_fields as its default type
multimatch
query requires match
queries as its internal queries. and a match
query doesn't support wildcards. Depending how we want to combine scores from multiple fields, we may use dis_max query 112, that can accept wildcard queries as well.
The best_fields
type generates a match
query for each field and wraps them in a dis_max
query, to find the single best matching field. For instance, this query:
GET /_search
{
"query": {
"multi_match" : {
"query": "king",
"type": "best_fields",
"fields": [ "text", "title" ],
"tie_breaker": 0.3
}
}
}
Copy as cURL[View in Console](http://localhost:5601/app/kibana#/dev_tools/console?load_from=https://www.elastic.co/guide/en/elasticsearch/reference/current/snippets/774.console
would be executed as:
GET /_search
{
"query": {
"dis_max": {
"queries": [
{ "match": { "subject": " king" }},
{ "match": { "message": " king" }}
],
"tie_breaker": 0.3
}
}
}
Copy as cURL[View in Console](http://localhost:5601/app/kibana#/dev_tools/console?load_from=https://www.elastic.co/guide/en/elasticsearch/reference/current/snippets/775.console
fields and per-field boosting
Fields can be specified with wildcards, eg:
"query": {
"multi_match" : {
"query": "king",
"fields": [ "title", "*_name" ]
}
}
different field mask
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"should": [
{"query": {"wildcard": {"text": {"value": "*king*"}}}},
{"query": {"wildcard": {"title": {"value": "*king*"}}}}
]
}
}
}
}
}`Preformatted text`