如果文档具有字段的映射不匹配,则Elasticsearch会静默失败 [英] Elasticsearch fails silently if document has mapping mismatch for a field
问题描述
long
。现在我不小心尝试索引一些文档,其中 c> string 的类型为<#c $ c> long 。我从Elasticsearch没有收到错误,但是这些文件从未被索引。当我修正这个问题时,文件索引很好。 示例:
我的映射:
{
field1:{
type:long
}
}
当我发送此文档时,它会静默地失败:
{
field1:这是一个字符串
}
当我发送它的工作原理:
{
field1:12345
}
有没有办法检测这种错误?
如果您设置 ignore_malformed 字符串为false。如果文档格式不正确但不会引发异常,则不会对文档编制索引。至少在弹性搜索1.6.0中。
示例:
put test
put test / test / _mapping
{
properties:{
title:{type:string},
data:{type:long,ignore_malformed:false}
}
}
put test / test / 1
{
data:1,
title:有效的强制字符串到数字
}
put test / test / 2
{
data:hello,
title:invalid number
}
#Failed Response
{
error:MapperParsingException [无法解析[data]];嵌套:NumberFormatException [对于输入字符串:\hello\];,
status:400
}
查询获取失败
获取测试/测试/ 2
{
_index:test ,
_type:test,
_id:2,
found:false
}
I am facing a weird issue with Elasticsearch. My mapping specifies that a certain field is of type long
. Now accidentally I was trying to index some documents which had string
type for that field instead of long
. I was getting no errors from Elasticsearch but the documents were never indexed. When I fixed the issue the documents were indexed just fine.
Example:
My mapping:
{
"field1": {
"type": "long"
}
}
When I send this document it fails silently:
{
"field1": "this is a string"
}
When I send this it works as expected:
{
"field1": 12345
}
Is there a way to detect this kind of errors?
If you set ignore_malformed string to false. It would not index the document if it is malformed but throws an exception. At least in elasticsearch 1.6.0.
Example:
put test
put test/test/_mapping
{
"properties" : {
"title" : {"type" : "string"},
"data" : {"type": "long" ,"ignore_malformed":false}
}
}
put test/test/1
{
"data" : "1",
"title" : "valid coerce string to number"
}
put test/test/2
{
"data" : "hello",
"title" : "invalid number"
}
#Failed Response
{
"error": "MapperParsingException[failed to parse [data]]; nested: NumberFormatException[For input string: \"hello\"]; ",
"status": 400
}
Query with Get fails
get test/test/2
{
"_index": "test",
"_type": "test",
"_id": "2",
"found": false
}
这篇关于如果文档具有字段的映射不匹配,则Elasticsearch会静默失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!