2017-08-06 107 views
0

我打算用嵌套字段定義映射。根據該documentation,有效載荷/order-statistics/_mapping/order樣子:elasticsearch:如何用嵌套字段定義映射?

{ 
    "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" 
       } 
      } 
      } 
     } 
     } 
    } 
    } 
    } 
} 

我已經創建了order-statistics指數與調用curl -XPUT 'localhost:9200/order-statistics',我使用預定義的類型,如intstringdouble,但我得到的出現以下錯誤並無法找到問題所在。

{ 
    "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 
} 

有人可以解釋爲什麼這不起作用嗎?

+0

你使用哪個版本,字符串在最新版本中被棄用,「int」應該是「整數」。 – MartinSchulze

回答

0

您正在使用int作爲在2.x或5.x中不是有效類型的某些字段的類型。對於整數值,請根據您要存儲的值使用integerlong。詳情請參閱the docs on core mapping types

您使用的是哪個版本的elasticsearch - 2.x或5.x?如果您已經使用5.x,則應該使用keywordtext作爲字符串字段,而不是僅使用string,該名稱最多爲2.x。但這仍然只是一個警告。

另外,您應該注意使用nested而不是僅僅使用object時的含義。如果您存儲對象數組並且希望查詢此類對象的多個屬性,並保證只有這些文檔與數​​組中嵌套的對象之一匹配所有條件,才能使用嵌套類型。但是這是有代價的,所以考慮使用簡單的object類型,如果這適合你。詳情請參閱the docs on nested data type,特別是the warning at the end

+0

我正在使用ES 5.5.1並將'int'更改爲'integer'對我有用。 – inherithandle