Elasticsearch Python - 索引分析器&搜索分析器

时间:2014-02-02 04:50:03

标签: python search elasticsearch

我正在使用python api - http://elasticsearch-py.readthedocs.org

如何设置更改索引的索引分析器和标记器?感谢

我找到了改变索引映射的建议,但是没有关于如何从python中做到这一点的文档。

Partial Search using Analyzer in ElasticSearch显示n-gram-analyzer的设置,但没有代码在python中实现它。

1 个答案:

答案 0 :(得分:8)

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
)

检查examples here.

相关问题