2017-02-15 23 views
2

假定以下文檔將被插入到Elasticsearch中。動態模板:以普通字符串存儲對象

{ 
    "message": "hello", 
    "request": { 
     "body": { 
      "data": "hi", 
      "some_what_dynamic": { 
       "nested": { 
        "not_ending": 10000 
       } 
      } 
     } 
    } 
} 

鑑於場request.body是已經嵌套在對象和/或領域的動態對象,我想存儲整個request.bodystring,我不想Elasticsearch創建內部request.body對象特性的新領域。

如何定義映射來實現這一目標?

這裏的電流dynamic_templates定義:

{ 
    "template": "logstash-*", 
    "mappings": { 
     "_default_": { 
      "dynamic_templates": [ 
       { 
        "message_field": { 
         "path_match": "message", 
         "mapping": { 
          "norms": false, 
          "type": "text" 
         }, 
         "match_mapping_type": "string" 
        } 
       }, 
       { 
        "string_fields": { 
         "mapping": { 
          "norms": false, 
          "type": "text", 
          "fields": { 
           "keyword": { 
            "type": "keyword" 
           } 
          } 
         }, 
         "match_mapping_type": "string", 
         "match": "*" 
        } 
       }, 
       { 
        "body_fields": { 
         "match": "body", 
         "mapping": { 
          "norms": false, 
          "type": "text" 
         }, 
         "match_mapping_type": "object" 
        } 
       } 
      ], 
      ... 
     } 
    } 
} 

當我嘗試插入文檔中,我得到了MapperParsingException有消息Can't get text on a START_OBJECT at...

回答

0

我想你只需要在雙引號中包裹body元素中的所有東西?像這樣的東西可能會工作(JavaScript)?

a={ 
    "message": "hello", 
    "request": { 
     "body": { 
      "data": "hi", 
      "some_what_dynamic": { 
       "nested": { 
        "not_ending": 10000 
       } 
      } 
     } 
    } 
}; 
a.request.body = JSON.stringify(a.request.body);