0
votes

Hi We wanted to suppot both partial search and exact match for one filed category.

Here is the mapping for category , We achieved this with fields.raw

"category": {
                    "properties": {
                        "name": {
                            "type": "string",
                            "analyzer": "autocomplete",
                            "search_analyzer": "standard",
                            "fields": {
                                "raw": {
                                   "type": "string",
                                   "index": "not_analyzed"
                                }
                             }
                        }
                    }
                }

Everything is working as expected , I am able to do both exact and partial search. But When I am having char comma "," in the data , Exact match is not working. I am searching with category.name.raw, which is not_analyzed filed

 { "query": {
"filtered": {
  "query": {
    "bool": {
      "must": [
        {
          "multi_match": {
            "query": "",
            "type": "cross_fields",
            "fields": [
              "filed1",
              "field2^12"
            ]
          }
        },
        {
          "match": {
            "category.name.raw": " Poverty, Poor and Hunger"
          }
        }
      ]
    }
  }
}}}

I am not getting any results, I am not sure what I am doing wrong, Please help me to fix this. Thanks in advance

2
which version of ES you are using, string is deprecated in latest versions.auser156327
@OpsterElasticsearchNinja We are using older version 2.X , Keyword data type is not supporting in this versionRamesh
@OpsterElasticsearchNinja 2.4.4 is the versionRamesh

2 Answers

0
votes

Try to use below analyzer:

        "lower_whitespace" : {
          "filter" : [
            "lowercase"
          ],
          "type" : "custom",
          "tokenizer" : "whitespace"
        }

for more details check below about tokenizers: https://www.elastic.co/guide/en/elasticsearch/reference/5.1/analysis-whitespace-analyzer.html

And it seems you using an old version from Elastic search consider upgrading will be a great idea

0
votes

The problem is

    {
      "match": {
        "category.name.raw": " Poverty, Poor and Hunger"
      }
    }

Whilst the targeted field is mapped as not_analyzed (aka keyword in newer versions of Elasticsearch), the query input here will be analyzed. I think it'll inherit the standard analyzer defined for the search_analyzer on category.name.

If you need an exact match, use a term query instead of the match query.