динамическое отображение для вложенного типа

У меня есть индекс/тип test1/all, который выглядит следующим образом:

{
  "test1": {
     "mappings": {
        "all": {
           "properties": {
              "colors": {
                 "properties": {
                    "H": {"type": "double"},
                    "S": {"type": "long"},
                    "V": {"type": "long"},
                    "color_percent": {"type": "long"}
                 }
              },
              "file_name": {
                 "type": "string"
              },
              "id": {
                 "type": "string"
              },
              "no_of_colors": {
                 "type": "long"
              }
           }
        }
     }
  }
}

Я хотел бы сделать поле цветов вложенным, я пытаюсь сделать следующее:

PUT /test1/all/_mapping
 {
  "mappings":{
          "all":{
              "properties": {
                  "file_name":{
                      "type": "string",
                      "index": "not_analyzed"
                  },
                  "id": {
                      "type": "string",
                      "index": "not_analyzed"
                  },
                  "no_of_colors":{
                  "type":"long",
                  "index": "not_analyzed"
                  },
                  "colors":{
                  "type":"nested",
                  "properties":{
                      "H":{"type":"double"},
                      "S":{"type":"long"},
                      "V":{"type":"long"},
                      "color_percent":{"type":"integer"}
                  }
                  }
              }     
          }
     }
}

Но я получаю следующую ошибку:

{
"error": "MapperParsingException[Root type mapping not empty after parsing!
Remaining fields:   [mappings : {all={properties={file_name={type=string, index=not_analyzed}, id={type=string, index=not_analyzed}, no_of_colors={type=integer, index=not_analyzed}, colors={type=nested, properties={H={type=double}, S={type=long}, V={type=long}, color_percent={type=integer}}}}}}]]",
 "status": 400
}

Какие-либо предложения? Цените помощь.


person venuktan    schedule 24.08.2016    source источник


Ответы (1)


Вы почти закончили, вам просто нужно удалить раздел mappings следующим образом:

PUT /test1/all/_mapping
{
  "properties": {
    "file_name": {
      "type": "string",
      "index": "not_analyzed"
    },
    "id": {
      "type": "string",
      "index": "not_analyzed"
    },
    "no_of_colors": {
      "type": "long",
      "index": "not_analyzed"
    },
    "colors": {
      "type": "nested",
      "properties": {
        "H": {
          "type": "double"
        },
        "S": {
          "type": "long"
        },
        "V": {
          "type": "long"
        },
        "color_percent": {
          "type": "integer"
        }
      }
    }
  }
}

Однако обратите внимание, что это тоже не сработает, потому что вы не можете изменить тип colors с object на nested, а другие строковые поля с analyzed на _not_analyzed. Вам нужно удалить свой индекс и заново создать его с нуля

person Val    schedule 24.08.2016
comment
хорошо, что работает. Но, как вы сказали, мне пришлось удалить и создать заново. Спасибо. - person venuktan; 25.08.2016