Search template mustache issue

67 Views Asked by At

I have an issue with my search template in ES 8.11,

It appears that there is data on the docName parameter, but there is no data when I search using the fulltext parameter and the docName parameter.

In this case, I need to search by docname and fulltext.

Is there any place in the template query where I can edit or add something?

Moreover, I have used five filters but only one is coming up in the search, even though I have used five.

I am using the search template for the first time, so I would appreciate any suggestions.

Here how I created my search template

PUT _scripts/wsed-search-template-testnew
{
  "script": {
    "lang": "mustache",
    "source": """
    {
      "query": {
        "bool": {
          "must": [
            {{#fulltext}}
            {
              "multi_match": {
                "query": "{{fulltext}}",
                "type": "most_fields",
                "fields": [
                  "docName^3",
                  "attachment.content^2",
                  "description"
                  ],
                  "minimum_should_match": "100%"
              }
            }
            {{/fulltext}}
            
            {{#content }}
            {
              "match": {
                "attachment.content": {
                  "query": "{{content}}",
                  "minimum_should_match": "100%"
                }
              }
            }  
            {{/content}}  
       
            {{#docname }}
            {
              "match": {
                "docName": {
                  "query": "{{docname}}",
                  "minimum_should_match": "100%"
                }
              }
            }
            {{/docname}} 
 ],
 
            "filter": [
              {
                "term": {
                  "isActive": {"value": true  }
                }
                
                {{#isDeleted}}
                "term": {
                  "isDeleted": {"value": false  }
                }  
                {{/isDeleted}}
                
                {{#clientid}}
                
                "term": {
                  "clientId": {"value": "{{clientid}}"}
                }
                {{/clientid}}
                
                
                {{#folderid}}
                
                "term": {
                  "folderId": {"value": "{{folderid}}"}
                }
                {{/folderid}}
                
                {{#doctypes}}
                {
                  "terms": {
                    "docType": {{#toJson}}doctype{{/toJson}}
                  }
                }
                {{/doctypes}}
                
                {{#createdby}}
                {
                  "term": {
                    "docCreatedBy": {{#toJson}}createdby{{/toJson}}
                  }
                }
                {{/createdby}}      
              }
              ]
              
        }
           
      },
      
      "rescore": [
        {{#fulltext}}
        {
          "window_size": 500,
          "query": {
            "rescore_query": {
              "multi_match": {
                "query": "{{fulltext}}",
                "type": "phrase",
                "fields" : [ "docName^3", "attachment.content^2","description" ],
                "slop": "{{slopfulltext}}"
                
              }},
              "rescore_query_weight" : 10
          }
        }
        {{/fulltext}}
        
        {{#docname}}
        {{#fulltext}},{{/fulltext}}
        {
          "window_size": 500,
          "query": {
            "rescore_query": {
              "match_phrase":{
                "docName":{
                  
                  "query": "{{docname}}",
                  "slop": "{{slopdocname}}"
                }
              }
            },
            "rescore_query_weight" : 10
          }
        }
        {{#content}},{{/content}}
        {{/docname}}
        
        {{#content}}
        {{#fulltext}}{{^docname}},{{/docname}}{{/fulltext}}
        {
          "window_size": 500,
          "query": {
            "rescore_query": {
              "match_phrase":{
                "attachment.content":{
                  "query": "{{content}}",
                  "slop": "{{slopcontent}}"
                }
              }
            },
            "rescore_query_weight" : 10
          }
        }
        {{/content}}
        ],
        
        "highlight": {
          "fields": {
            "docName":{"number_of_fragments" : 0,"no_match_size":200},
            "description":{"number_of_fragments" : 0,"no_match_size":200}
          }
        },
        "sort":[
          {{#sortcolumn}}
          {
            "{{sortcolumn}}": "{{orderby}}"
          }   
          {{/sortcolumn}} ],
          
          "from" : "{{pageno}}{{^pageno}}0{{/pageno}}",
          "size" : "{{recordcount}}{{^recordcount}}200{{/recordcount}}"
          
    }"""
  }
}

Search will be

GET wsentdocrepo/_search/template
{
  "id": "wsed-search-template-testnew",
  "params": {
    "docname": "insurance-123",
    "fulltext": "AZI"
  }
}

And getting error

{
  "error": {
    "root_cause": [
      {
        "type": "x_content_parse_exception",
        "reason": """[20:2] Unexpected character (',' (code 44)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (String)"
    {
      "query": {
        "bool": {
          "must": [
            {
              "multi_match": {
                "query": "policy",
                "type": "most_fields",
                "fields": [
                  "docName^3",
                  "attachment.content^2",
                  "description"
                  ],
                  "minimum_should_match": "100%"
              }
            }
            ],
            "filter": [
,
,
,
,
,
              {
                "matc"[truncated 2374 chars]; line: 20, column: 2]"""
      }
    ],
    "type": "x_content_parse_exception",
    "reason": "[20:1] [bool] failed to parse field [filter]",
    "caused_by": {
      "type": "x_content_parse_exception",
      "reason": """[20:2] Unexpected character (',' (code 44)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (String)"
    {
      "query": {
        "bool": {
          "must": [
            {
              "multi_match": {
                "query": "policy",
                "type": "most_fields",
                "fields": [
                  "docName^3",
                  "attachment.content^2",
                  "description"
                  ],
                  "minimum_should_match": "100%"
              }
            }
            ],
            "filter": [
,
,
,
,
,
              {
                "matc"[truncated 2374 chars]; line: 20, column: 2]""",
      "caused_by": {
        "type": "json_parse_exception",
        "reason": """Unexpected character (',' (code 44)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
 at [Source: (String)"
    {
      "query": {
        "bool": {
          "must": [
            {
              "multi_match": {
                "query": "policy",
                "type": "most_fields",
                "fields": [
                  "docName^3",
                  "attachment.content^2",
                  "description"
                  ],
                  "minimum_should_match": "100%"
              }
            }
            ],
            "filter": [
,
,
,
,
,
              {
                "matc"[truncated 2374 chars]; line: 20, column: 2]"""
      }
    }
  },
  "status": 400
}
0

There are 0 best solutions below