2016-06-02 3 views
0

Я пытаюсь создать динамический шаблон для вложенного объекта.Динамический шаблон ElasticSearch для вложенных

Вот документ индекс:

{ 
    "title": "My title", 
    "attributes": { 
     "color": { 
      "id": 42, 
      "label": "red" 
     }, 
     "material": { 
      "id": 43, 
      "label": "textile" 
     } 
    } 
} 

Это шаблон я безуспешно пытался

{ 
    "dynamic": "false", 
    "dynamic_templates": [ 
    { 
     "attributes": { 
     "path_match": "attributes", 
     "mapping": { 
      "type": "nested" 
     } 
     } 
    }, 
    { 
     "attributes_nested": { 
     "path_match": "attributes.*", 
     "mapping": { 
      "properties": { 
      "id": { 
       "type": "integer" 
      }, 
      "value": { 
       "type": "string" 
      } 
      } 
     } 
     } 
    } 
    ], 
    "properties": { 
    "title": { 
     "type": "string" 
    } 
    } 
} 

Я хотел бы быть в состоянии сделать агрегированные на attributes.color.id и attributes.material.id

ответ

0

Nevermind, проблема заключалась в том, что я имел

{ "dynamic": false} 

Правильное картирование

{ 
    "dynamic": "false", 
    "dynamic_templates": [ 
    { 
     "attributes_nested": { 
     "path_match": "attributes.*", 
     "mapping": { 
      "properties": { 
      "id": { 
       "type": "integer" 
      }, 
      "value": { 
       "type": "string" 
      } 
      } 
     } 
     } 
    } 
    ], 
    "properties": { 
    "title": { 
     "type": "string" 
    }, 
    "attributes": { 
     "type": "nested", 
     "dynamic": true 
    } 
    } 
} 
Смежные вопросы