[英]How to create an Elasticsearch mapping with not_analyzed nested fields?
[英]elasticsearch: how to define mapping with nested fields?
我將定義帶有嵌套字段的映射。 根據此文檔 , /order-statistics/_mapping/order
有效負載如下所示:
{
"mappings" : {
"order": {
"properties" : {
"order_no" : {
"type" : "string"
},
"order_products" : {
"type" : "nested",
"properties" : {
"order_product_no" : {
"type" : "int"
},
"order_product_options" : {
"type" : "nested",
"properties" : {
"order_product_option_no" : {
"type" : "int"
}
}
}
}
}
}
}
}
}
我已經通過調用curl -XPUT 'localhost:9200/order-statistics'
創建了order-statistics
索引,並且我正在使用預定義類型,例如int
, string
, double
,但是出現以下錯誤並且可以'找不到問題所在。
{
"error":{
"root_cause":[
{
"type":"mapper_parsing_exception",
"reason":"Root mapping definition has unsupported parameters: [mappings : {order={properties={order_no={type=string}, order_products={type=nested, properties={order_product_no={type=int}, order_product_options={type=nested, properties={order_product_option_no={type=int}}}}}}}}]"
}
],
"type":"mapper_parsing_exception",
"reason":"Root mapping definition has unsupported parameters: [mappings : {order={properties={order_no={type=string}, order_products={type=nested, properties={order_product_no={type=int}, order_product_options={type=nested, properties={order_product_option_no={type=int}}}}}}}}]"
},
"status":400
}
有人可以解釋為什么這行不通嗎?
您正在將int
用作某些字段的類型,這在2.x或5.x中都不是有效的類型。 對於整數值,請根據要存儲的值使用integer
或long
。 有關詳細信息,請參閱有關核心映射類型的文檔 。
您正在使用哪個版本的elasticsearch-2.x或5.x? 如果您已經在5.x上,則應該在字符串字段中使用keyword
或text
,而不是僅使用命名為2.x的string
。 但這仍然只是警告。
此外,使用nested
而不是object
時,您應該意識到其中的含義。 如果您存儲對象數組並要查詢此類對象的多個屬性,並且必須保證只有這些文檔與數組中嵌套對象之一匹配所有條件的位置匹配,則必須使用嵌套類型。 但這是有代價的,因此,如果適合您,請考慮使用簡單的object
類型。 有關更多詳細信息,請參閱有關嵌套數據類型的文檔 ,尤其是末尾的警告 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.