I have started work on a search template and hit a snag when trying to add a terms query to the template. Here is the template definition:
POST _scripts/establishments_search
{
"script": {
"lang": "mustache",
"source": {
"size": "{{size}}{{^size}}3{{/size}}",
"query": {
"bool": {
"must": [
{
"match": {
"cityID": {
"query": "{{cityID}}{{^cityID}}*{{/cityID}}",
"_name": "CityID"
}
}
},
{
"match": {
"countryAffiliation": {
"query": "{{countryAffiliation}}{{^countryAffiliation}}*{{/countryAffiliation}}",
"_name": "CountryAffiliation"
}
}
},
{
"terms": {
"_name": "EstablishmentAliases",
"establishmentAliases": "{{establishmentAliases}}{{^establishmentAliases}}*{{/establishmentAliases}}"
}
}
],
"should": [
{
"match": {
"overtFunction.keyword": {
"query": "{{overtFunction}}{{^overtFunction}}*{{/overtFunction}}",
"_name": "OvertFunction",
"boost": "{{overtFunctionBoost}}{{^overtFunctionBoost}}1{{/overtFunctionBoost}}"
}
}
}
]
}
}
}
}
}
Here is the sample record I am testing against:
PUT establishments/_doc/1
{
"establishmentAliases": [ "acme", "acme inc", "acme incorporated" ],
"cityID": 1234,
"countryAffiliation": "US",
"overtFunction": "Sales",
"requiredMatches": 1,
"Addresses": [
{
"Address": "1917 Blair Ave",
"City": "Hanover",
"State": "MD"
},
{
"Address": "111 East Bell Ave",
"City": "Johnstown",
"State": "PA"
}
]
}
The problem with the template is the establishmentAliases field (which is defined as a keyword field in my mapping) but I can run this query directly against the index and get the expected result:
GET establishments/_search
{
"query": {
"nested": {
"path": "Addresses",
"query": {
"bool": {
"should": [
{
"match": {
"Addresses.Address": "1917"
}
},
{
"match": {
"Addresses.City": "Hanover"
}
},
{
"match": {
"Addresses.State": "MD"
}
},
{
"terms": {
"establishmentAliases": [
"Acme",
"Acme inc."
]
}
}
]
}
}
}
}
}
However, this template search generates the error below:
GET establishments/_search/template
{
"id": "establishments_search",
"params": {
"cityID": 1234,
"establishmentAliases": ["acme", "acme inc"],
"countryAffiliation": "US",
"size": 3,
"overtFunction": "Sales",
"overtFunctionBoost": 1
}
}
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[terms] query does not support [establishmentAliases]",
"line": 1,
"col": 234
}
],
"type": "x_content_parse_exception",
"reason": "[1:234] [bool] failed to parse field [must]",
"caused_by": {
"type": "parsing_exception",
"reason": "[terms] query does not support [establishmentAliases]",
"line": 1,
"col": 234
}
},
"status": 400
}
Anyone have any ideas on how to wire in a terms query into a search template? They way I have it wired in does not look right but I cannot figure out the correct format. Lastly, if I remove the establishmentAliases terms piece from the search template the template works as expected. Any help that anyone could provide would be appreciated. Thanks.
Kevin