2017-04-18 139 views
1

我有不同類型的彈性搜索索引。 每種類型都包含一些默認字段和一些基於類型的額外字段。 每種類型都有位置對象,可以存儲緯度和經度。我在我的彈性搜索索引 的樣本數據是彈性搜索非法參數異常

[{ 
    "_index": "es_index", 
    "_type": "type1", 
    "_id": "id1", 
    "_source": { 
     "name": "name", 
     "type1field": "value", 
     "location": { 
      "lat": 1, 
      "lon": 1 
     } 
    } 
}, { 
    "_index": "es_index", 
    "_type": "type2", 
    "_id": "id2", 
    "_source": { 
     "name": "name", 
     "type2field": "value", 
     "location": { 
      "lat": 1, 
      "lon": 1 
     } 
    } 
}] 

我能夠創建通過「感」,但得到從Java應用程序中的錯誤同樣映射的索引。

我使用「org.springframework.data.elasticsearch.core.ElasticsearchTemplate」從我的Java應用程序創建彈性搜索索引。

我正在使用相同的ElasticsearchTemplate來保存和查詢數據。

當所有的不同類型有不同的對應文件創建索引,它是成功的,但是在保存數據,我得到錯誤的

​​3210

而且我在所有的有「位置」相同的映射類型

"location": { 
       "geohash": true, 
       "lat_lon": true, 
       "store": true, 
       "type": "geo_point" 
      } 

FYI-這裏是我的es_index映射

{ 
"es_index": { 
    "aliases": { 
     "es_index1": {} 
    }, 
    "mappings": { 

     "type1": { 
      "properties": { 
       "field1": { 
        "type": "string", 
        "analyzer": "nGram_analyzer", 
        "search_analyzer": "whitespace_analyzer" 
       }, 
       "field2": { 
        "type": "string", 
        "index": "no" 
       }, 
       "field3": { 
        "type": "string", 
        "analyzer": "nGram_analyzer", 
        "search_analyzer": "whitespace_analyzer" 
       }, 
       "field4": { 
        "type": "string", 
        "index": "no" 
       }, 
       "location": { 
        "type": "geo_point", 
        "store": true, 
        "lat_lon": true, 
        "geohash": true 
       } 
      } 
     }, 

     "type2": { 
      "properties": { 
       "field1": { 
        "type": "string", 
        "analyzer": "nGram_analyzer", 
        "search_analyzer": "whitespace_analyzer" 
       }, 
       "field5": { 
        "type": "string", 
        "analyzer": "nGram_analyzer", 
        "search_analyzer": "whitespace_analyzer", 
        "include_in_all": true 
       }, 
       "field4": { 
        "type": "string", 
        "index": "no" 
       }, 
       "location": { 
        "type": "geo_point", 
        "store": true, 
        "lat_lon": true, 
        "geohash": true 
       }, 
       "field6": { 
        "type": "string", 
        "index": "no" 
       } 

      } 



     } 
    }, 
    "settings": { 
     "index": { 
      "creation_date": "1491466792565", 
      "include_in_all": "false", 
      "uuid": "uuid....", 
      "number_of_replicas": "1", 
      "analysis": { 
       "filter": { 
        "nGram_filter": { 
         "max_gram": "75", 
         "type": "edgeNGram", 
         "min_gram": "2", 
         "token_chars": [ 
          "letter", 
          "digit", 
          "punctuation", 
          "symbol" 
         ] 
        } 
       }, 
       "analyzer": { 
        "nGram_analyzer": { 
         "type": "custom", 
         "filter": [ 
          "lowercase", 
          "asciifolding", 
          "nGram_filter" 
         ], 
         "tokenizer": "keyword" 
        }, 
        "whitespace_analyzer": { 
         "type": "custom", 
         "filter": [ 
          "lowercase", 
          "asciifolding" 
         ], 
         "tokenizer": "keyword" 
        } 
       } 
      }, 
      "number_of_shards": "8", 
      "version": { 
       "created": "2040499" 
      } 
     } 
    }, 
    "warmers": {} 
} 
} 

瓦在這是它的原因,我該如何解決它?

+0

你可以發佈你的索引映射嗎? 'curl localhost:9200/es_index?pretty' – fylie

+0

@fylie:我編輯了問題 – Raghavendra

回答

0

錯誤消息表明您嘗試在同一索引中以兩種不同方式(在不同的文檔類型中)映射相同的字段名稱。

  • 發生這種情況可能是因爲您實際上編寫了此重複映射。
  • 如果打開動態映射並且在更新使用相同名稱的其他類型的映射之前插入了包含該字段名稱的文檔,也可能會發生這種情況。

您無法在同一個索引中以兩種不同方式映射字段。

舉例來說,如果你有...

"mappings": { 
    "books": { 
     "properties":{ 
     "title":{ 
      "type":"text" 
     }, 
     ... 

您以後不能在同一指數...

"films": { 
     "properties":{ 
     "title":{ 
      "type":"keyword" 
     } 
     } 

標題字段中只有一個索引映射定義。

標題字段爲索引中的所有類型共享。

類型不像數據庫表。

  • 他們在Lucene索引中共享字段。
  • 他們有點像一個大共享索引的觀點。

如果這是你正在經歷什麼,你有三種選擇:

  1. 作出的位置字段爲索引中的所有文檔類型相同的映射。 (這對於類似位置的東西似乎是個好主意。)

  2. 在不同的文檔類型中使用不同的字段名稱作爲位置。

  3. 對需要不同映射定義的位置的文檔類型使用單獨的索引。

如果這只是動態映射進入並破壞索引的情況,那麼考慮關閉它。想象一下在生產中發生這種情況會有多快樂。

+0

我想這個問題已經被回答了很多次。對於Elasticsearch的新手來說,這是第一次粗魯的覺醒,並期望它像典型的數據庫一樣行事。 – joshp

+0

在我的情況下,第二和第三選擇被排除。 而且我對所有類型都有相同的映射。 「位置」:{ 「地理散列」:真實, 「lat_lon」:真實, 「存儲」:真實, 「類型」: 「geo_point」 } 不過還是我收到此錯誤,任何其他這可能發生的原因? – Raghavendra

+0

我也更新了這個問題。當我嘗試使用「sense」時,我能夠使用相同的映射創建索引。但是java應用程序沒有發生同樣的情況。 @joshp – Raghavendra