Everytime I use the same query, such as code below:
{
"bool": {
"should": [
{
"multi_match" : {
"query": "Will Smith",
"type": "cross_fields",
"fields": [ "first", "last" ],
"minimum_should_match": "50%"
}
},
{
"multi_match" : {
"query": "Will Smith",
"type": "cross_fields",
"fields": [ "*.edge" ]
}
}
]
}}
Each time I use different query word, but the params are the same.
Does elasticsearch support this kind of strategy we can define, like ranking strategy? Each time I just need to input the query.
Elasticsearch supports template query where you can register a query and pass the query string as a param
Example:
PUT <server::port>/.scripts
PUT <server::port>/_search/template/<template_name> { "template": { "query": { "bool": { "should": [ { "multi_match": { "query": "{{query_string}}", "type": "cross_fields", "fields": [ "first", "last" ], "minimum_should_match": "50%" } }, { "multi_match": { "query": "{query_string}", "type": "cross_fields", "fields": [ "*.edge" ] } } ] } }
} }
POST <server::port>/index>/_search/template { "template": { "id": "<template_name>" }, "params": { "query_string": "will smith" } }