Hi everyone. I have a question of using script for searching query phrasy through 4 index fields with several different cluases in script. Each script will have it's own clauses.
Script for searching through 4 fields:
PUT _scripts/liquid_instruments_search_date
{
"script": {
"lang": "mustache",
"source": {
"query": {
"bool": {
"must": [
{
"match": {
"isLiquidBoard": "true"
}
},
{
"match": {
"isDefaultUniversalExchange": "true"
}
},
{
"match":{
"isEnabled":"true"
}
},
{
"bool": {
"should": [
{
"range": {
"matDate": {
"gte": "{{gte}}",
"lte": "{{lte}}"
}
}
},
{
"bool": {
"must_not": [
{
"exists": {
"field": "matDate"
}
}
]
}
}
]
}
},
{
"bool": {
"should": [
{
"match": {
"ticker": {
"query": "{{query_string}}",
"fuzziness": 1,
"boost": 4
}
}
},
{
"match": {
"name": {
"query": "{{query_string}}",
"fuzziness": 1,
"boost": 3
}
}
},
{
"match": {
"assetSynonyms": {
"query": "{{query_string}}",
"fuzziness": 1,
"boost": 2
}
}
},
{
"match": {
"assetCode": {
"query": "{{query_string}}",
"fuzziness": 2,
"boost": 1
}
}
}
]
}
}
]
}
},
"from": "{{from}}{{^from}}0{{/from}}",
"size": "{{size}}{{^size}}10{{/size}}"
},
"params": {
"query_string": "query string"
}
}
}
Script for different clauses:
PUT _scripts/multipurpose_template
{
"script": {
"lang": "mustache",
"source": """{"sort": {{#toJson}}sort{{/toJson}},"from":"{{from}}","size":"{{size}}","query":{"bool":{"must":{{#toJson}}clauses{{/toJson}}}}}"""
}
}
How can I unite these two scripts above?
Example of data in index:
"_source" : {
"emShortName" : "Set net value inc",
"emitent" : 397650,
"nominalCurr" : "RUB",
"expared" : false,
"ticker" : "RU000A0JUD00",
"adfrontType" : "corporate",
"allowNonQualInvest" : true,
"emCode" : "IAVS2012",
"boardName" : "МБ ЦК T+1",
"hellGroup" : "Облигации",
"universalExchangeId" : 1,
"cupPeriod" : 92,
"lot" : 1,
"universalMarketCode" : "MOEX_TQ1_RUB",
"isEnabled" : true,
"actId" : 61377,
"cupSize" : 0.0,
"currency" : "RUB",
"matDate" : "2046-08-11",
"isin" : "RU000A0JUD00",
"assetCode" : "RU000A0JUD00",
"nkdCurr" : "RUB",
"faceUunit" : 174368,
"riskCurrency" : "RUR",
"isTradeAccess" : false,
"isLiquidBoard" : true,
"hellType" : "Bonds",
"nkd" : 0.0,
"isDefaultUniversalExchange" : true,
"objectId" : 397651,
"regCode" : "4-04-79226-H",
"displayGroup" : 105,
"name" : "Вост.-Сиб.ипот.агент 2012 кл.А",
"nominal" : 4.22,
"complexProduct" : "",
"adfrontGroup" : "Bonds",
"cupDate" : "2023-11-11",
"bondTypeName" : "Corporate",
"idfi" : 158875,
"dailyPiPercent" : 0.0,
"sessionDate" : "2024-05-14",
"price" : 102.0
}
}