在轮胎的弹搜索映射中禁用日期检测

时间:2021-01-27 00:11:22

I'm indexing a document with a property obj_properties, which is a hash of property name -> property value. elasticsearch is inferring that some of the property values are dates, leading to the following error when it encounters a subsequent value for the same property that can't be parsed as a date.

我使用属性obj_properties对文档进行索引,它是属性名的散列——>属性值。elasticsearch可以推断,某些属性值是日期,当遇到无法解析为日期的同一属性的后续值时,将导致以下错误。

org.elasticsearch.index.mapper.MapperParsingException: failed to parse date field <NON-DATE FIELD within obj_properties>

org.elasticsearch.index.mapper。MapperParsingException:无法解析obj_properties>中的date字段 字段

So, I'd like to disable date detection for obj_properties and anything nested within it. Per

因此,我想禁用obj_properties和其中嵌套的任何东西的日期检测。每

http://elasticsearch-users.115913.n3.nabble.com/Date-Detection-not-always-wanted-tp1638890p1639415.html

http://elasticsearch-users.115913.n3.nabble.com/Date-Detection-not-always-wanted-tp1638890p1639415.html

(Note, I believe the linked post contains a typo -- the field should be date_formats rather than date_format, but I've tried both ways)

(注意,我认为链接的文章包含一个排版错误——字段应该是date_formats而不是date_format,但是我尝试了两种方式)

I've created the following mapping

我创建了以下映射

mapping do
    indexes :name
    indexes :obj_properties, type: "object", date_formats: "none"
  end

but I continue to receive the same exception. The properties in obj_properties are not known ahead of time, so it's not possible to create an exhaustive mapping of types. Any ideas? Is disabling date detection the correct approach?

但我继续收到相同的异常。obj_properties中的属性事先不知道,所以不可能创建类型的详尽映射。什么好主意吗?禁用日期检测是正确的方法吗?

2 个解决方案

#1


2  

You can turn off date detection for a particular type by specifying it in the mapping:

您可以通过在映射中指定特定类型来关闭日期检测:

curl -XPUT 'http://127.0.0.1:9200/myindex/?pretty=1'  -d '
{
   "mappings" : {
      "mytype" : {
         "date_detection" : 0
      }
   }
}
'

or for all types in an index by specifying it in the default mapping:

或在默认映射中指定索引中的所有类型:

curl -XPUT 'http://127.0.0.1:9200/myindex/?pretty=1'  -d '
{
   "mappings" : {
      "_default_" : {
         "date_detection" : 0
      }
   }
}
'

#2


1  

mapping(date_detection: false) do
  indexes :name
  indexes :obj_properties, type: "object"
end

then curl 'http://127.0.0.1:9200/myindex/_mapping?pretty=1' will include date_detection = false mentioned here

然后旋度“http://127.0.0.1:9200 myindex / _mapping吗?pretty=1'将包含date_detection = false

Although i believe this applies to the entire index - not a particular field

尽管我认为这适用于整个索引——而不是一个特定的字段

#1


2  

You can turn off date detection for a particular type by specifying it in the mapping:

您可以通过在映射中指定特定类型来关闭日期检测:

curl -XPUT 'http://127.0.0.1:9200/myindex/?pretty=1'  -d '
{
   "mappings" : {
      "mytype" : {
         "date_detection" : 0
      }
   }
}
'

or for all types in an index by specifying it in the default mapping:

或在默认映射中指定索引中的所有类型:

curl -XPUT 'http://127.0.0.1:9200/myindex/?pretty=1'  -d '
{
   "mappings" : {
      "_default_" : {
         "date_detection" : 0
      }
   }
}
'

#2


1  

mapping(date_detection: false) do
  indexes :name
  indexes :obj_properties, type: "object"
end

then curl 'http://127.0.0.1:9200/myindex/_mapping?pretty=1' will include date_detection = false mentioned here

然后旋度“http://127.0.0.1:9200 myindex / _mapping吗?pretty=1'将包含date_detection = false

Although i believe this applies to the entire index - not a particular field

尽管我认为这适用于整个索引——而不是一个特定的字段