具有不支持的参数的根映射定义

时间:2019-09-19 15:15:54

标签: elasticsearch

  • 弹性搜索版本: 7.3.2
  • 在那里使用的所有文档均来自this tutorial

我已从此链接导入了文件movies_elastic.json。当我在http://localhost:9200/movies/?pretty处进行查询时,我收到了一个JSON文档,该文档为我提供了文档的每个键的类型和分析方式:关键字,文本,长,浮点,日期。

{
  "movies" : {
    "aliases" : { },
    "mappings" : {
      "properties" : {
        "fields" : {
          "properties" : {
            "actors" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "directors" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "genres" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "image_url" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "plot" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "rank" : {
              "type" : "long"
            },
            "rating" : {
              "type" : "float"
            },
            "release_date" : {
              "type" : "date"
            },
            "running_time_secs" : {
              "type" : "long"
            },
            "title" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "year" : {
              "type" : "long"
            }
          }
        },
        "id" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "type" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }
    },
    "settings" : {
      "index" : {
        "creation_date" : "1568894285856",
        "number_of_shards" : "1",
        "number_of_replicas" : "1",
        "uuid" : "4tvtLNrTRuij4-a0hGBZFQ",
        "version" : {
          "created" : "7030299"
        },
        "provided_name" : "movies"
      }
    }
  }
}

我数据库中文本的默认映射包括关键字“ keyword”,我现在想转换不需要原始分析的任何字段,这些原始分析允许直接获取数据而无需分析。

我尝试使用以下方法为新的“ movies2”索引加载映射:

curl -XPUT -H "Content-Type: application/json" localhost:9200/movies2 -d @mapping_movies/mapping.json

但是我遇到以下错误:

JSON
error
root_cause
0
type : "mapper_parsing_exception"
reason : "Root mapping definition has unsupported parameters: [movie : {properties={id={type=text, fields={keyword={ignore_above=256, type=keyword}}}, fields={properties={actors={type=text, fields={raw={index=false, type=text}}}, plot={type=text, fields={keyword={ignore_above=256, type=keyword}}}, release_date={type=date}, year={type=long}, genres={type=text, fields={raw={index=false, type=text}}}, image_url={type=text, fields={raw={index=false, type=text}}}, directors={type=text, fields={raw={index=false, type=text}}}, rating={type=float}, rank={type=long}, title={type=text, fields={keyword={ignore_above=256, type=keyword}}}, running_time_secs={type=long}}}, type={type=text, fields={keyword={ignore_above=256, type=keyword}}}}}]"
type : "mapper_parsing_exception"
reason : "Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [movie : {properties={id={type=text, fields={keyword={ignore_above=256, type=keyword}}}, fields={properties={actors={type=text, fields={raw={index=false, type=text}}}, plot={type=text, fields={keyword={ignore_above=256, type=keyword}}}, release_date={type=date}, year={type=long}, genres={type=text, fields={raw={index=false, type=text}}}, image_url={type=text, fields={raw={index=false, type=text}}}, directors={type=text, fields={raw={index=false, type=text}}}, rating={type=float}, rank={type=long}, title={type=text, fields={keyword={ignore_above=256, type=keyword}}}, running_time_secs={type=long}}}, type={type=text, fields={keyword={ignore_above=256, type=keyword}}}}}]"
caused_by
type : "mapper_parsing_exception"
reason : "Root mapping definition has unsupported parameters: [movie : {properties={id={type=text, fields={keyword={ignore_above=256, type=keyword}}}, fields={properties={actors={type=text, fields={raw={index=false, type=text}}}, plot={type=text, fields={keyword={ignore_above=256, type=keyword}}}, release_date={type=date}, year={type=long}, genres={type=text, fields={raw={index=false, type=text}}}, image_url={type=text, fields={raw={index=false, type=text}}}, directors={type=text, fields={raw={index=false, type=text}}}, rating={type=float}, rank={type=long}, title={type=text, fields={keyword={ignore_above=256, type=keyword}}}, running_time_secs={type=long}}}, type={type=text, fields={keyword={ignore_above=256, type=keyword}}}}}]"
status : 400

在下面的映射中,我更改了演员,导演,流派和URL的类型。因此,这些字段确实是文本(类型),但作为原始数据进行分析(字段:{raw:{raw:{type:“ keyword”}}}):

{
    "mappings" : {
      "movie" : {
        "properties" : {
          "fields" : {
            "properties" : {
              "actors" : {
                "type" : "text",
                "fields" : {
                  "raw" : {
                    "type" : "text",
                    "index" : false
                  }
                }
              },
              "directors" : {
                "type" : "text",
                "fields" : {
                  "raw" : {
                    "type" : "text",
                    "index" : false
                  }
                }
              },
              "genres" : {
                "type" : "text",
                "fields" : {
                  "raw" : {
                    "type" : "text",
                    "index" : false
                  }
                }
              },
              "image_url" : {
                "type" : "text",
                "fields" : {
                  "raw" : {
                    "type" : "text",
                    "index" : false
                    }
                }
              },
              "plot" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
              "rank" : {
                "type" : "long"
              },
              "rating" : {
                "type" : "float"
              },
              "release_date" : {
                "type" : "date"
              },
              "running_time_secs" : {
                "type" : "long"
              },
              "title" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
              "year" : {
                "type" : "long"
              }
            }
          },
          "id" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "type" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          }
        }
      }
    }
}

我的猜测是我尝试的命令不是最新的用于Elastic 7.3.2的

更新

我遵循瓦尔的建议,并做了以下映射文件:

{
    "aliases" : { },
    "mappings" : {

        "properties" : {
          "fields" : {
            "properties" : {
              "actors" : {
                "type" : "text",
                "fields" : {
                  "raw" : {
                    "type" : "text",
                    "index" : false
                  }
                }
              },
              "directors" : {
                "type" : "text",
                "fields" : {
                  "raw" : {
                    "type" : "text",
                    "index" : false
                  }
                }
              },
              "genres" : {
                "type" : "text",
                "fields" : {
                  "raw" : {
                    "type" : "text",
                    "index" : false
                  }
                }
              },
              "image_url" : {
                "type" : "text",
                "fields" : {
                  "raw" : {
                    "type" : "text",
                    "index" : false
                    }
                }
              },
              "plot" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
              "rank" : {
                "type" : "long"
              },
              "rating" : {
                "type" : "float"
              },
              "release_date" : {
                "type" : "date"
              },
              "running_time_secs" : {
                "type" : "long"
              },
              "title" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              },
              "year" : {
                "type" : "long"
              }
            }
          },
          "id" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "type" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          }
        }

    }
}

但是我无法导入新数据。以下命令

curl -XPUT -H "Content-Type: application/json" localhost:9200/_bulk --data-binary @mapping_movies/movies_elastic2.json

给我以下错误:

{
  "took": 44239,
  "errors": true,
  "items": [
    {
      "index": {
        "_index": "movies2",
        "_type": "movie",
        "_id": "1",
        "status": 400,
        "error": {
          "type": "illegal_argument_exception",
          "reason": "Rejecting mapping update to [movies2] as the final mapping would have more than 1 type: [_doc, movie]"
        }
      }
    },
    {
      "index": {
        "_index": "movies2",
        "_type": "movie",
        "_id": "2",
        "status": 400,
        "error": {
          "type": "illegal_argument_exception",
          "reason": "Rejecting mapping update to [movies2] as the final mapping would have more than 1 type: [_doc, movie]"
        }
      }
    },
    {
      "index": {
        "_index": "movies2",
        "_type": "movie",
        "_id": "3",
        "status": 400,
        "error": {
          "type": "illegal_argument_exception",
          "reason": "Rejecting mapping update to [movies2] as the final mapping would have more than 1 type: [_doc, movie]"
        }
      }
    },
    {
      "index": {
        "_index": "movies2",
        "_type": "movie",
        "_id": "4",
        "status": 400,
        "error": {
          "type": "illegal_argument_exception",
          "reason": "Rejecting mapping update to [movies2] as the final mapping would have more than 1 type: [_doc, movie]"
        }
      }
    },
    {
      "index": {
        "_index": "movies2",
        "_type": "movie",
        "_id": "5",
        "status": 400,
        "error": {
          "type": "illegal_argument_exception",
          "reason": "Rejecting mapping update to [movies2] as the final mapping would have more than 1 type: [_doc, movie]"
        }
      }
    },
...

2 个答案:

答案 0 :(得分:0)

您的映射文件必须如下所示:

{
   "aliases" : { },
   "mappings" : {
      "properties" : {
         "fields" : {
            ...

所以:

  • 删除顶级movies部分
  • 删除movie类型

还请注意,您无法使用_bulk端点定义映射,您需要删除索引并重新创建索引,如下所示:

# delete the index
curl -XDELETE -H "Content-Type: application/json" localhost:9200/movies2

# recreate it
curl -XPUT -H "Content-Type: application/json" localhost:9200/movies2 --data-binary @mapping_movies/movies_elastic2.json

你很好走

答案 1 :(得分:0)

"Rejecting mapping update to [INDEX] as the final mapping would have more than 1 type: [_doc, TYPE]"

这通常意味着INDEX已经存在(类型为例如“电影”),并且ES不允许再添加一种类型(例如“ _doc”)。因此,只需删除索引,然后重试。