簡體   English   中英

如何告訴ElasticSearch創建嵌套字段

[英]How to tell ElasticSearch to create nested fields

我將數據放入ES並檢查創建的映射,

我正在執行此操作:

curl -XPOST 'http://localhost:9200/testnested2/type1/0' -d '{
  "p1": ["1","2","3","4"], 
   "users" : {
      "first" : "John",
      "last" :  "Sm11ith" 
   }
}'

這是它創建的架構:

{
  "testnested2":{
     "mappings":{
       "type1":{
          "properties":{
            "p1":{"type":"string"},
            "users":{
              "properties":{
                 "first":{"type":"string"},
                 "last":{"type":"string"}
               }
            }
         }
       }
     }
   }
}

我想知道是否可以告訴它“用戶”是嵌套的,還是我必須為自己創建映射。

我希望ES可以像這樣創建一個shema:

   curl -XPOST http://180.5.5.93:9200/testnested3 -d '{
        "settings" : {
            "number_of_shards" : 1
        },
        "mappings" : {  
        "type1" : {
            "properties" : {
                "propiedad1" : { "type" : "string"},
                "users" : {
                    "type" : "nested",
                    "include_in_parent": true,
                    "properties": {
                        "first" : {"type": "string" },
                        "last"  : {"type": "string" }
                    }
                }
            }
        }
        }
    }'

默認情況下,ElasticSearch的動態映射功能會將users映射為object而不是nested

如果要調整此行為,則必須顯式定義一個nestedusers屬性:

  • type1映射
  • 索引的默認映射。 這樣,對於創建的任何類型, users屬性將自動設置為nested (有關默認映射信息,請參見此處

暫無
暫無

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

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