16

I have an embedded elasticsearch using the elasticsearch-jetty project, and I need to setup to use tokenizers better than the defaults. I want to use the keyword tokenizer.

I can't figure out for the life of me how to do this through the config files. Can anyone point me at a way to do this through config files?

As an aside, is it possible to adjust the index while it's up and running by doing a POST to the index? I'd really like to understand how to use this, thank you.

EDIT/update: I'm having trouble running curl -XPUT or -XPOST to localhost:9200 to try to adjust settings from some of the examples/forums I've seen when searching to help here, I'm getting results of 'No handler for uri [] and method [PUT]/[POST].

EDIT 2: Update, doing XPUT to an index works, but I get an error about "Index already exists". I know it exists, I want to update it.

cdietschrun
  • 1,623
  • 6
  • 23
  • 39

2 Answers2

27

You can define mappings in the config files, but for most cases it is easier/more flexible to configure through the API. For example, this command will add a keyword/lowercase analyzer to the index test:

$ curl -XPUT localhost:9200/testindex/ -d '
{
  "settings":{
     "index":{
        "analysis":{
           "analyzer":{
              "analyzer_keyword":{
                 "tokenizer":"keyword",
                 "filter":"lowercase"
              }
           }
        }
     }
  },
  "mappings":{
     "test":{
        "properties":{
           "title":{
              "analyzer":"analyzer_keyword",
              "type":"string"
           }
        }
     }
  }
}'
Zach
  • 9,591
  • 1
  • 38
  • 33
  • 1
    Thanks for the reply. I tried to do an XPUT for an index that currently exists, and got an error about the index already existing. Can you help me understand? Is it possible to edit an existing index? – cdietschrun Feb 26 '13 at 01:30
  • 2
    If an index has already been created, you can use the PUT mapping API to alter the mapping: http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping.html. Note though, you can't change a property's mapping once it's been created. If you need to change a property, you'll have to create a new index with a new mapping – Zach Feb 26 '13 at 01:37
  • I have created the Custom Analyser and am able to see it in _settings. but as i am using nest .net client, i am not able to add it to the Auto Mapped Properties. by adding [Text(Analyzer = "analyzer_keyword")]. Please Guide – N.K Oct 11 '18 at 11:35
0

To update an existing index, use

$ curl -XPUT localhost:9200/testindex/_settings -d '
{
..........
}

However you can't update non dynamic settings.

Simson
  • 829
  • 6
  • 16
sld
  • 59
  • 2