2015-06-10 50 views
3

我正在尝试添加自定义分析器。创建索引后创建自定义分析器

curl -XPUT 'http://localhost:9200/my_index' -d '{ 
    "settings" : { 
     "analysis" : { 
      "filter" : { 
       "my_filter" : { 
        "type" : "word_delimiter", 
        "type_table": [": => ALPHA", "/ => ALPHA"] 
       } 
      }, 
      "analyzer" : { 
       "my_analyzer" : { 
        "type" : "custom", 
        "tokenizer" : "whitespace", 
        "filter" : ["lowercase", "my_filter"] 
       } 
      } 
     } 
    } 
}' 

它工作在我的本地环境时,我可以我想每次都重新创建索引时,问题就来了,当我尝试做同样在其他环境中,如QA或督促,其中该指数已创建。

{ 
    "error": "IndexAlreadyExistsException[[my_index] already exists]", 
    "status": 400 
} 

如何通过HTTP API添加我的自定义分析器?

回答

4

documentation我发现,更新索引设置,我可以做到这一点:

curl -XPUT 'localhost:9200/my_index/_settings' -d ' 
{ 
    "index" : { 
     "number_of_replicas" : 4 
    } 
}' 

,并更新分析仪设置的documentation说:

” ...它需要关闭该指数首先在修改完成后打开它。“

所以我落得这样做的:

curl -XPOST 'http://localhost:9200/my_index/_close' 

curl -XPUT 'http://localhost:9200/my_index' -d '{ 
    "settings" : { 
     "analysis" : { 
      "filter" : { 
       "my_filter" : { 
        "type" : "word_delimiter", 
        "type_table": [": => ALPHA", "/ => ALPHA"] 
       } 
      }, 
      "analyzer" : { 
       "my_analyzer" : { 
        "type" : "custom", 
        "tokenizer" : "whitespace", 
        "filter" : ["lowercase", "my_filter"] 
       } 
      } 
     } 
    } 
}' 

curl -XPOST 'http://localhost:9200/my_index/_open' 

这对我来说固定的一切。

+2

除了'_close'和'_open',我发现'curl -XPUT'http:// localhost:9200/my_index/_settings'与_settings'端点并不直接'PUT'到'/ my_index'。相应地调整json级别。 –