2017-08-06 106 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