Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ElasticSearch 5:MapperParserException在插入数据时发生异常 - Fatal编程技术网

ElasticSearch 5:MapperParserException在插入数据时发生异常

ElasticSearch 5:MapperParserException在插入数据时发生异常,
Warning: implode(): Invalid arguments passed in /data/phpspider/zhask/webroot/tpl/detail.html on line 45
,,我最初的映射是 { "vehiclemodel": { "properties": { "price": { "type": "double" } } } } 后来,我更新了下面的映射 { "vehiclemodel": { "properties": { "price": { "type": "double", "fields": { "exShowro

我最初的映射是

{
  "vehiclemodel": {
    "properties": {
      "price": {
        "type": "double"
      }
    }
  }
}
后来,我更新了下面的映射

{
  "vehiclemodel": {
    "properties": {
      "price": {
        "type": "double",
        "fields": {
          "exShowroomPrice": {
            "type": "double"
          }
        }
      }
    }
  }
}
现在,当我添加Data1时,它会被添加,但当我添加Data2时,它会抛出下面的异常

数据1

{
  "price": 36992043     
}
{
  "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]'
            }
        }
    }
}
数据2

{
  "price": 36992043     
}
{
  "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]'
            }
        }
    }
}
异常

{
  "price": 36992043     
}
{
  "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]'
            }
        }
    }
}

我的收藏
vehiclemodel
MongoDB中包含这两种类型的数据。我正在使用mongo连接器来同步数据,顺便说一下mongo和ES。当我尝试同步时,我得到了上述异常,elasticsearch映射中的字段被认为以不同的方式索引同一字段,例如将输入字段作为字符串或关键字处理。因此,您将price定义为double,但elasticsearch会找到一个{},因此会引发此异常。您必须在那里重新建模您的数据。

您的映射与我认为您想要实现的目标不符

例如,映射允许您使用不同的分析器对相同的字段编制索引(有关详细信息,请参阅链接文档)。所以在你的情况下,你会推

{
    "price" : 1923
}
ES将存储它两次,一次作为
price
,一次存储在路径
price.exShowroomPrice

您可以只添加一个完全独立的属性,不需要维护层次结构。例如,映射如下:

{
    "vehiclemodel": {
        "properties": {
            "price": {
                "type": "double"
            },
            "exShowroomPrice": {
                "type": "double"
            }
        }
    }
}
然后发送数据,如:

{
    "price" : 1923
    "exShowroomPrice" : 1800
} 

我不知道mongo connector是如何工作的,但我认为应该有一种方法来映射这些字段。

对我来说,重新构建数据有点困难。那么,是否有更新映射的选项,以便我可以插入这两种类型的数据?是的,您可以保留“price”:double并添加一个简单的exShowroomPrice:double。这里的
exShowroomPrice
是一个单独的字段。在我的例子中,我希望
exShowroomPrice
嵌套在
price
下,并且我希望需要插入Data1和Datat2。下面是我提到的更新映射的方法,这可能是不可能的,因为在Data1
price
中它是一个double,而在Data2中它是一个object。