ElasticSearch 5:插入数据时出现MapperParserException [英] ElasticSearch 5: MapperParserException while Inserting data
问题描述
我最初的映射是
{
"vehiclemodel": {
"properties": {
"price": {
"type": "double"
}
}
}
}
后来我用以下内容更新了映射
Later I updated the mapping with below
{
"vehiclemodel": {
"properties": {
"price": {
"type": "double",
"fields": {
"exShowroomPrice": {
"type": "double"
}
}
}
}
}
}
现在,当我添加 Data1 时,它会添加,但是当我添加 Data2 会在异常以下抛出
Now when I add Data1 it getting added, but when I add Data2 it throws below exception
Data1 :
{
"price": 36992043
}
数据2 :
{
"price": {
"exShowroomPrice": 36992043
}
}
例外:
{
'index': {
'_index': 'notes',
'_type': 'vehiclemodel',
'_id': 'fb85823a-021b-468c-91d9-8db5f001ee06',
'status': 400,
'error': {
'type': 'mapper_parsing_exception',
'reason': 'failed to parse [price]',
'caused_by': {
'type': 'json_parse_exception',
'reason': 'Current token (START_OBJECT) not numeric, can not use numeric value accessors\n at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@6e2393ee; line: 1, column: 277]'
}
}
}
}
我的收藏集车辆模型
在 MongoDB 中具有两种类型的数据。我正在使用mongo-connector在mongo和ES之间同步数据。当我尝试同步时,出现上述异常
My collectionvehiclemodel
has both type of data in MongoDB. I am using mongo-connector to sync data btw mongo and ES. When I try to sync I get the above exception
推荐答案
对于您认为要实现的目标,您的映射不正确。
Your mapping is not correct for what I assume you want to achieve.
字段映射,您可以例如使用不同的分析器为同一字段建立索引(有关详细信息,请参见链接的文档)。因此,在您的情况下,您可以按
The fields mapping allows you to index the same field with different analyzers for example (see the linked docs for details). So in your case, you would push
{
"price" : 1923
}
,ES会将其存储两次,一次为价格
,然后只需在路径 price.exShowroomPrice
下。
and ES will store it twice, once as price
and once under the path price.exShowroomPrice
.
您只需添加一个完全独立的属性,层次结构就不需要保持。例如这样的映射:
You could just add a completely separate property, the hierarchy does not need to be maintained. For example a mapping like:
{
"vehiclemodel": {
"properties": {
"price": {
"type": "double"
},
"exShowroomPrice": {
"type": "double"
}
}
}
}
然后像这样发送数据:
{
"price" : 1923
"exShowroomPrice" : 1800
}
我不知道mongo-connector的工作原理,但是应该有一种方法可以映射这些字段会承担。
I don't know how mongo-connector works, but there should be a way to map these fields I would assume.
这篇关于ElasticSearch 5:插入数据时出现MapperParserException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!