2

I want to put a new mapping to a index without deleting the index. Elasticsearch::Model does not seem to provide an API for this. Or do I miss it?

3 Answers 3

2

1 Login to your elastic search client

require 'elasticsearch'
client = Elasticsearch::Client.new log: true

2 Create new index with mapping data

client.indices.create index: 'testindex', body: {
   "mappings": {
    "dynamic": false,
    "properties": {
      title: { type: 'text' }
    }
  }
}

3 checked your newly created index

client.indices.get_mapping index: "testindex"
Sign up to request clarification or add additional context in comments.

Comments

0

You can PUT a new mapping over the old mapping without deleting any data or dropping the index. The catch is that updated field mappings only get applied to new data, not existing data. If you want the new mapping to be applied to old data then you need to re-index.

1 Comment

Indeed. I would have to reindex everything. My question was about how to change the mapping using the elasticsearch-ruby API.
0

Given the Elasticsearch client, you can update the existing field mappings like this:

client.indices.put_mapping index: 'myindex', type: 'mytype', body: {
  mytype: {
    properties: {
      title: { type: 'string', analyzer: 'snowball' }
    }
  }
}

See https://github.com/elastic/elasticsearch-ruby/blob/master/elasticsearch-api/lib/elasticsearch/api/actions/indices/put_mapping.rb#L50

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.