Elasticsearch: Mapping with Index not_analyzed is not working

Created on 26 Oct 2016  路  7Comments  路  Source: elastic/elasticsearch

Elasticsearch version: 5.0.0-rc1

Plugins installed: [none]

JVM version:

java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

OS version: Debian 8

Description of the problem including expected versus actual behavior:

Creating an example index with its mapping:

PUT twitter 
{
  "mappings": {
    "tweet": {
      "properties": {
        "message": {
          "type": "text",
          "index": "not_analyzed"
        }
      }
    }
  }
}

Everything went fine:

{
  "acknowledged": true
}

But now, let's get the actual mapping with GET twitter/_mapping/tweet:

{
  "twitter": {
    "mappings": {
      "tweet": {
        "properties": {
          "message": {
            "type": "text"
          }
        }
      }
    }
  }
}

The message field is still analyzed. Why?

:SearcMapping >bug help wanted

Most helpful comment

Hi @olivierlambert it is unfortunate that we accept this mapping without barfing. text means analyzed text in elasticsearch 5.0. index became a boolean property, that is why setting it to not_analyzed doesn't have any effect. If you want to have a non analyzed field, you need to use "type": "keyword".

All 7 comments

Hi @olivierlambert it is unfortunate that we accept this mapping without barfing. text means analyzed text in elasticsearch 5.0. index became a boolean property, that is why setting it to not_analyzed doesn't have any effect. If you want to have a non analyzed field, you need to use "type": "keyword".

This looks like a side-effect of the fact that we wanted to make the migration easier by interpreting analyzed and not_analyzed as index: true, and no as index: false. For the new text and keyword types, this looks more error-prone than helpful however.

Thanks lads for your input :) I let you decide what to do with this issue :+1:

I digged this with @johtani and templates are relying on this behaviour so that templates created on 2.x keep working in 5.0, even if they generate mappings for string fields. Making mappings strict while keeping the feature in templates seems hard so we are leaning towards keeping things as they are today.

I am also facing the same issue. My index is already created. so how to change that field from text type to keyword type.

I am also facing the same issue . @prashuMishra Do you have a solution ?

This can't be changed on an existing index, you would need to create a new index with correct mappings, and reindex to it, possibly via the reindex API.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

matthughes picture matthughes  路  3Comments

jasontedor picture jasontedor  路  3Comments

Praveen82 picture Praveen82  路  3Comments

rpalsaxena picture rpalsaxena  路  3Comments

abrahamduran picture abrahamduran  路  3Comments