christinabo
christinabo

Reputation: 1130

ElasticSearch: Can I query the .raw field?

I am attempting to query the .raw version of a field that I have in my elasticsearch (version 5.0.0) index. The name of the field is 'region' and its mapping is the following:

{

  "properties": {
    "region": {
      "type": "text", "analyzer": "custom_analyzer", 
      "fields": {
        "raw": { 
              "type":  "keyword", "index": "not_analyzed"
        }
      }
    }
  }
}

Note that I had initially set the region mapping with the analyzed version and in the second step I updated the mapping by adding the raw version of the field.

As far as I understood from the documentation and a similar question here, I can query the raw field to get the documents whose regions exactly match my query. However, by using the following query, no results are returned.

{
   "match": {
        "region.raw": "Northern Ireland"
   }
}

In contrary, by using the analyzed version of my field, the results are returned as expected.

{
   "match": {
        "region": "Northern Ireland"
   }
}

As I need to use the raw field, I have the following questions:

Thank you very much for your help.

Upvotes: 6

Views: 9944

Answers (1)

betto86
betto86

Reputation: 714

Nope, you query is correct. The problem is that you have to reindex your data in order to index with the new mapping version.

Upvotes: 7

Related Questions