Search code examples
elasticsearchelasticsearch-mapping

change elasticsearch mapping


I am trying to change the mapping using following code:

PUT /in_test/_mapping/keyword
{
 "properties" : {
            "term" : {
                "type" : "text",
                "index" : "not_analyzed" 
            }
        }
}

But it is giving an error:

{
  "error": {
"root_cause": [
  {
    "type": "remote_transport_exception",
    "reason": "[tiebreaker-0000000000][172.17.0.24:19555][indices:admin/mapping/put]"
  }
],
"type": "illegal_argument_exception",
"reason": "Could not convert [term.index] to boolean",
"caused_by": {
  "type": "illegal_argument_exception",
  "reason": "Failed to parse value [not_analyzed] as only [true] or [false] are allowed."
}
},
"status": 400
}

I also tried to recreate the index by:

PUT /in_test
 {
"mappings" : {
    "keyword" : {
        "properties" : {
            "term" : {
                "type" : "text",
                "index" : "not_analyzed" 
            }
        }
    }
}
}

but I got:

{
 "error": {
"root_cause": [
  {
    "type": "mapper_parsing_exception",
    "reason": "Failed to parse mapping [keyword]: Could not convert [term.index] to boolean"
  }
],
"type": "mapper_parsing_exception",
"reason": "Failed to parse mapping [keyword]: Could not convert [term.index] to boolean",
"caused_by": {
  "type": "illegal_argument_exception",
  "reason": "Could not convert [term.index] to boolean",
  "caused_by": {
    "type": "illegal_argument_exception",
    "reason": "Failed to parse value [not_analyzed] as only [true] or [false] are allowed."
  }
}
 },
 "status": 400
 }

I also tried to change the _type to keywords but it is still not working. Basically, I want to search for exact match of string and for that I am referring to this:

https://www.elastic.co/guide/en/elasticsearch/guide/current/_finding_exact_values.html#_term_query_with_text


Solution

  • That documentation page is from Elasticsearch version 2.X (See at the top of the page), and is no longer correct for modern versions of Elasticsearch.

    The error you're getting is because "index" now only accepts true or false, and refers to whether or not the property is indexed at all - Since you're searching by this property, you want it to be true (the default).

    Instead, try setting the type to "keyword" and it won't be tokenized. https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-keyword-analyzer.html#_definition_5

    PUT /in_test
    {
    "mappings" : {
        "keyword" : {
            "properties" : {
                "term" : {
                    "type" : "keyword"
                }
            }
         }
    }
    }