弹性搜索非法参数异常

问题描述:

我有不同类型的弹性搜索索引。 每种类型都包含一些默认字段和一些基于类型的额外字段。 每种类型都有位置对象,可以存储纬度和经度。我在我的弹性搜索索引 的样本数据是弹性搜索非法参数异常

[{ 
    "_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

错误消息表明您尝试在同一索引中以两种不同方式(在不同的文档类型中)映射相同的字段名称。

  • 发生这种情况可能是因为您实际上编写了此重复映射。
  • 如果打开动态映射并且在更新使用相同名称的其他类型的映射之前插入了包含该字段名称的文档,也可能会发生这种情况。

您无法在同一个索引中以两种不同方式映射字段。

举例来说,如果你有...

"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