2015-04-14 62 views
0

我試圖用不同的分析器建立索引來進行索引和搜索。 的意義上,我鍵入下面的代碼:如何在ES中使用不同分析器創建索引以進行搜索和索引?

PUT my_index 
{ 
    "mappings" : { 
     "my_type" : { 
     "properties" : { 
      "content" : { 
       "type" : "string", 
       "index": "analyzed", 
       "analyzer": "my_index_analyzer" 
      } 
     } 
     } 
    }, 
    "settings" : { 
     "number_of_shards" : 1, 
     "analysis" : { 
       "filter" : { 
        "my_filter" : { 
         "type" : "pattern_capture", 
         "preserve_original" :1, 
         "patterns" : ["(([a-z]+)(\\d*))"]           
          }}, 
       "index_analyzer" : { 
        "my_index_analyzer" : { 
         "tokenizer" : "standard", 
         "type" : "custom", 
         "filter" : ["my_filter"] 
           }}, 
       "search_analyzer" : { 
        "my_search_analyzer" : { 
         "type" : "custom", 
         "tokenizer" : "standard", 
         "filter" : ["standard", "lowercase"] 
       } 
      } 
     } 
    } 
} 

但這似乎並沒有工作; ES實例總是給我返回一個錯誤,如

MapperParsingException [mapping [my_type]];嵌套: MapperParsingException [分析[my_index_analyzer]沒有發現 場[內容]

回答

1

您的分析部分更改爲

"analyzer": { 
     "my_index_analyzer" : { 
      "tokenizer" : "standard", 
      "type" : "custom", 
      "filter" : ["my_filter"] 
     }, 
     "my_search_analyzer" : { 
      "type" : "custom", 
      "tokenizer" : "standard", 
      "filter" : ["standard", "lowercase"] 
     } 
     } 
    } 

和映射部分更改爲:

"properties" : { 
     "content" : { 
      "type" : "string", 
      "index": "analyzed", 
      "index_analyzer": "my_index_analyzer", 
      "search_analyzer": "my_search_analyzer" 
     } 
     } 
相關問題