1

我想在ElasticSearch中創建一個嵌套的文檔。elasticsearch映射解析器異常

結構: 標題,名稱,評論 評論是一個嵌套的文件 - 內部 - 評論& Star_Rating。 內部評論,名稱和地址。

這裏是下面提到的查詢。

PUT /sounduu 
    { 
    "mappings": { 
     "blogpost": { 
      "properties": { 
       "title": { 
        "type": "string" 
       }, 
       "name": { 
        "type": "string" 
       }, 
       "comments": { 
        "properties": { 
         "comment": { 
          "properties": { 
           "name": { 
            "type": "string" 
           }, 
           "address": { 
            "type": "string" 
           } 
          } 
         }, 
         "star_rating": { 
          "type": "long" 
         } 
        } 
       } 
      } 
     } 
    } 
} 


PUT /sounduu/blogpost/1 
{ 
    "title": "someh_title", 
    "name":"soundy", 
    "comments": { 
     "comment":"kuu", 
     [{ 
      "name":"juwww", 
      "address":"eeeey" 
     }, 
     { 
      "name":"jj", 
      "address":oo" 
     }] 
    }, 
    "star_rating":6 
} 

錯誤:

{ 
    "error": { 
     "root_cause": [ 
     { 
      "type": "mapper_parsing_exception", 
      "reason": "object mapping for [comments.comment] tried to parse field [comment] as object, but found a concrete value" 
     } 
     ], 
     "type": "mapper_parsing_exception", 
     "reason": "object mapping for [comments.comment] tried to parse field [comment] as object, but found a concrete value" 
    }, 
    "status": 400 
} 

任何人都可以在這方面幫助?

回答

0

在您的PUT /sounduu/blogpost/1請求中,您試圖將「comment」屬性視爲嵌套對象和字符串。

格式化您的要求的JSON,你可以觀察到的問題:

{ 
    "title": "someh_title", 
    "name": "soundy", 
    "comments": { 
     "comment": "kuu", 
     [{ 
      "name": "juwww", 
      "address": "eeeey" 
     }, 
     { 
      "name": "jj", 
      "address": oo" 
     }] 
    }, 
    "star_rating":6 
} 

要麼你需要更新你的映射包含一個「文本」屬性,並相應地移動"comment": "kuu"內容,或者從您的請求中省略,使用您當前的映射。

例在這裏 - 對於我來說,似乎是合乎邏輯組的一切,像這樣:

PUT /sounduu 
    { 
    "mappings": { 
     "blogpost": { 
      "properties": { 
       "title": { 
        "type": "string" 
       }, 
       "name": { 
        "type": "string" 
       }, 
       "comments": { 
        "properties": { 
         "text" : { 
          "type": "string" 
         }, 
         "name": { 
          "type": "string" 
         }, 
         "address": { 
          "type": "string" 
         } 
        } 
       }, 
       "star_rating": { 
        "type": "long" 
       } 
      } 
     } 
    } 
} 

索引請求將隨後樣子:

{ 
    "title": "someh_title", 
    "name": "soundy", 
    "comments": [ 
     { 
      "text": "kuu", 
      "name": "juwww", 
      "address": "eeeey" 
     }, 
     { 
      "text": "kuu2", 
      "name": "jj", 
      "address": oo" 
     } 
    ], 
    "star_rating":6 
} 
+0

ryanlutgen - 感謝您的回覆。如何使用「文本」屬性更新映射並移動評論內容? –

+0

我已經編輯了我的答案,並舉例說明了在這種情況下我會做什麼。 – ryanlutgen

+0

感謝您的回答。同樣的情況也適用於我!但是我期待的是,例如,我期待在文本中嵌入更多的文檔。 –