0

I'm looking how to increase the length of a string in elastic search. This post, UTF8 encoding is longer than the max length 32766, says that in order to do that I need to do one of the following:

1) change the type to binary
2) to continue to use string but set the index type to "no"

How would I do either of these?

Community
  • 1
  • 1
Adrian
  • 5,603
  • 8
  • 53
  • 85

1 Answers1

1

You will need to change the mapping for the field and then re-index the data - you cannot change a mapping for a field after you've indexed data into it.

If you are unfamiliar with the concept of mappings within Elasticsearch or the Put mappings API, I'd start reading here:

http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/mapping-intro.html

and here:

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-put-mapping.html

Assuming you wanted to created a field as binary, you'd do something like this:

$ curl -XPUT 'http://localhost:9200/yourindex/yourtype/_mapping' -d '
{
    "yourtype" : {
        "properties" : {
            "yourbigstring" : {"type" : "binary", "store" : true }
        }
    }
}
'

and if you want to leave it as a string but not analyzed:

$ curl -XPUT 'http://localhost:9200/yourindex/yourtype/_mapping' -d '
{
    "yourtype" : {
        "properties" : {
            "yourbigstring" : {"type" : "string", "store" : true, "index" : "not_analyzed"}
        }
    }
}
'
John Petrone
  • 26,943
  • 6
  • 63
  • 68
  • Very helpful! Do you know where I can find how to set the index mapping via Java API calls? I can never find anything on ES site. – Adrian Jul 24 '14 at 15:48
  • A couple of examples: http://stackoverflow.com/questions/22071198/adding-mapping-to-a-type-from-java-how-do-i-do-it and http://stackoverflow.com/questions/17292668/elasticsearch-adding-manual-mapping-using-java – John Petrone Jul 24 '14 at 16:44
  • @John Petrone Why do you advice to set "not_analyzed" (the second example) for a big string now if it's exactly the cause of problem? – SerG Sep 10 '14 at 13:05