2015-06-10 48 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級別。 –