7

I am using python api - http://elasticsearch-py.readthedocs.org

How can I set change the index analyzer and tokenizer for the index? Thanks

I found suggestions to change the mapping of the index, but there was no documentation on how to do that from python.

Partial Search using Analyzer in ElasticSearch shows settings for n-gram-analyzer but no code to implement it in python.

1 Answer 1

14
client.indices.create(
    index=index,
    body={
      'settings': {
        # just one shard, no replicas for testing
        'number_of_shards': 1,
        'number_of_replicas': 0,

        # custom analyzer for analyzing file paths
        'analysis': {
          'analyzer': {
            'file_path': {
              'type': 'custom',
              'tokenizer': 'path_hierarchy',
              'filter': ['lowercase']
            }
          }
        }
      }
    },
    # Will ignore 400 errors, remove to ensure you're prompted
    ignore=400
)

Check the examples here.

Sign up to request clarification or add additional context in comments.

3 Comments

The use of ignore=400 would cause this request to fail silently if an index already exists. You probably want to see an error in this case :)
@DrTech added further info.

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.