Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch Python - Index Analyzer & Search Analyzer

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.

like image 492
Pratik Poddar Avatar asked Feb 02 '14 04:02

Pratik Poddar


1 Answers

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.

like image 153
Nathan Smith Avatar answered Sep 30 '22 01:09

Nathan Smith