2016-04-21 37 views
0

我已經創建了一個指數Elasticsearch以下設置:「MapperParsingException [分析[秒]沒有發現場[名]」

{ 
    "my_index" : { 
    "aliases" : { }, 
    "mappings" : { }, 
    "settings" : { 
     "index" : { 
     "creation_date" : "1461229073677", 
     "uuid" : "7-TECarfRs6XO8yZE7SeWA", 
     "number_of_replicas" : "1", 
     "number_of_shards" : "5", 
     "version" : { 
      "created" : "1040599" 
     }, 
     "settings" : { 
      "analysis" : { 
      "analyzer" : { 
       "second" : { 
       "type" : "custom", 
       "filter" : [ "lowercase", "synonym" ], 
       "tokenizer" : "standard" 
       } 
      }, 
      "filter" : { 
       "synonym" : { 
       "type" : "synonym", 
       "synonyms" : [ "i pad => ipad", "smart phone => smartphone" ] 
       } 
      } 
      } 
     } 
     } 
    }, 
    "warmers" : { } 
    } 
} 

現在我想要做是設置映射使用以下代碼:

PutMapping putMapping = new PutMapping.Builder(
     "my_index", 
     "my_index_type", 
     "{ \"properties\" : { \"Name\" : {\"type\" : \"string\", \"analyzer\" : \"second\"} } }" 
).build(); 


JestResult result = client.execute(createIndex); 
result = client.execute(putMapping); 

EDIT

我米使用來創建索引的代碼是:

CreateIndex createIndex = new CreateIndex.Builder(indexName) 
.settings( 
     ImmutableSettings.builder() 
       .loadFromClasspath(
         "settings.json" 
       ).build().getAsMap() 
).build(); 
JestResult result = client.execute(createIndex); 

和settings.json看起來是這樣的:

{ 
    "settings": { 
    "analysis": { 
     "analyzer": { 
     "second": { 
      "type": "custom", 
      "tokenizer": "standard", 
      "filter": [ 
      "lowercase", 
      "synonym" 
      ] 
     } 
     }, 
     "filter": { 
     "synonym" : { 
      "type" : "synonym", 
      "synonyms" : [ 
       "i pad => ipad", 
       "smart phone => smartphone", 
       "i phone => iphone" 
       ]    
        } 
       } 
     } 

    } 
} 

不過,我不斷收到以下錯誤:

"MapperParsingException[Analyzer [second] not found for field [message]]" 

我能夠設置映射如果刪除「分析」。因此,似乎我有兩次「設置」部分,但無論如何構造「settings.json」文件,我都會收到這兩部分內容。我查看了JEST頁面中指定的示例,但沒有幫助我。 https://github.com/searchbox-io/Jest/blob/master/jest/README.md

任何想法傢伙?

回答

2

你使用不正確定義的設置,即你有兩個疊瓦狀settings部分,該指數的設置應該是這樣的,而不是:

{ 
    "my_index": { 
    "aliases": {}, 
    "mappings": {}, 
    "settings": { 
     "index": { 
     "number_of_replicas": "1", 
     "number_of_shards": "5" 
     }, 
     "analysis": { 
     "analyzer": { 
      "second": { 
      "type": "custom", 
      "filter": [ 
       "lowercase", 
       "synonym" 
      ], 
      "tokenizer": "standard" 
      } 
     }, 
     "filter": { 
      "synonym": { 
      "type": "synonym", 
      "synonyms": [ 
       "i pad => ipad", 
       "smart phone => smartphone" 
      ] 
      } 
     } 
     } 
    }, 
    "warmers": {} 
    } 
} 

UPDATE

settings.json文件只需要包含以下內容:

{ 
    "analysis": { 
    "analyzer": { 
     "second": { 
     "type": "custom", 
     "filter": [ 
      "lowercase", 
      "synonym" 
     ], 
     "tokenizer": "standard" 
     } 
    }, 
    "filter": { 
     "synonym": { 
     "type": "synonym", 
     "synonyms": [ 
      "i pad => ipad", 
      "smart phone => smartphone" 
     ] 
     } 
    } 
    } 
} 
+0

是的你是對的。我可以使用CURL創建一個「設置」部分的索引。但是當我使用JEST庫時,我總是以兩個結束。 我編輯了我的問題,以便您可以看到我正在使用的「settings.json」。你能否看看並讓我知道如果需要以不同的方式構建它? – panipsilos

+0

我已更新我的回答 – Val

+0

Thnx,它的工作!我之前已經嘗試過(刪除「設置」部分),但實際情況是Eclipse沒有更新「settings.json」,並且我一直在獲取相同的結構(使用雙「設置」部分)。我花了一段時間才弄明白,很多挫折。我現在每次在settings.json中進行更改時,都會刷新項目,以便Eclipse加載剛剛更改的文件。 乾杯和thnx爲你的幫助 – panipsilos