2013-02-11 61 views
3

我使用屬性obj_properties(它是屬性名稱 - >屬性值的散列)對文檔建立索引。 elasticsearch推斷某些屬性值是日期,當遇到無法解析爲日期的同一屬性的後續值時導致以下錯誤。在Tire的elasticsearch映射中禁用日期檢測

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

所以,我想禁用日期檢測obj_properties和任何嵌套在。每

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

(注意,我相信鏈接的帖子包含一個錯字 - 字段應該是date_formats而非date_format,但我已經試過兩種方式)

我創建了以下映射

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

但我繼續收到相同的異常。 obj_properties中的屬性未提前知道,因此無法創建類型的詳盡映射。有任何想法嗎?禁用日期檢測是否正確?

回答

2

可以通過在映射指定它關閉日期檢測針對特定type

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

或用於在索引中的所有類型的由默認映射將其指定:

curl -XPUT 'http://127.0.0.1:9200/myindex/?pretty=1' -d ' 
{ 
    "mappings" : { 
     "_default_" : { 
     "date_detection" : 0 
     } 
    } 
} 
' 
1
mapping(date_detection: false) do 
    indexes :name 
    indexes :obj_properties, type: "object" 
end 

然後curl 'http://127.0.0.1:9200/myindex/_mapping?pretty=1'將包括date_detection = false提到的here

雖然我認爲這適用於整個指數 - 不是一個特定的領域