Hi everyone.
I'm trying to make a template wich I can use to search through several fields by one word (using query string). But now I need to add a clause which will get a variable in a query (date). How can I combine search with query string with a variable clause?
My template looks like this now:
PUT _scripts/template_id
{
"script": {
"lang": "mustache",
"source": {
"query": {
"bool": {
"must": [
{
"match": {
"field_1": "true"
}
},
{
"match": {
"field_2": "true"
}
},
{
"match":{
"field_3":"true"
}
},
{
"bool": {
"should": [
{
"match": {
"field_4": {
"query": "{{query_string}}",
"fuzziness": "1",
"boost": 4
}
}
},
{
"match": {
"field_5": {
"query": "{{query_string}}",
"fuzziness": "1",
"boost": 4
}
}
},
{
"match": {
"field_6": {
"query": "{{query_string}}",
"fuzziness": "1",
"boost": 4
}
}
},
{
"match": {
"field_7": {
"query": "{{query_string}}",
"fuzziness": "1",
"boost": 1
}
}
}
]
}
}
]
}
},
"from": "{{from}}{{^from}}0{{/from}}",
"size": "{{size}}{{^size}}10{{/size}}"
},
"params": {
"query_string": "Query string"
}
}
}
GET instruments_keyword/_search/template
{
"id": "template_id",
"params": {
"query_string": "apple",
"range": {
"Date": {
"gte": "2023-05-17",
"lte": "2100-01-01"
}
}
"from": 0,
"size": 1280
}
}
So I need to use date range in my query of template and the date must be variable.