簡體   English   中英

elasticsearch:如何定義嵌套字段的映射?

[英]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索引,並且我正在使用預定義類型,例如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
}

有人可以解釋為什么這行不通嗎?

您正在將int用作某些字段的類型,這在2.x或5.x中都不是有效的類型。 對於整數值,請根據要存儲的值使用integerlong 有關詳細信息,請參閱有關核心映射類型的文檔

您正在使用哪個版本的elasticsearch-2.x或5.x? 如果您已經在5.x上,則應該在字符串字段中使用keywordtext ,而不是僅使用命名為2.x的string 但這仍然只是警告。

此外,使用nested而不是object時,您應該意識到其中的含義。 如果您存儲對象數組並要查詢此類對象的多個屬性,並且必須保證只有這些文檔與數​​組中嵌套對象之一匹配所有條件的位置匹配,則必須使用嵌套類型。 但這是有代價的,因此,如果適合您,請考慮使用簡單的object類型。 有關更多詳細信息,請參閱有關嵌套數據類型的文檔 ,尤其是末尾的警告

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM