【问题标题】:ElasticSearch Illegal Argument ExceptionElasticSearch 非法参数异常
【发布时间】:2017-04-29 18:30:50
【问题描述】:

我在 Ubuntu 16.04 上使用 Elasticsearch 最新版本,但在将数据放在上面时遇到了一点问题。

这是我的 json 文档(相关部分)

{   "products" : {
    "232CDFDW89ENUXRB" : {
        "sku" : "232CDFDW89ENUXRB",
        "productFamily" : "Compute Instance",
        "attributes" : {
            "servicecode" : "AmazonEC2",
            "location" : "US East (N. Virginia)",
            "locationType" : "AWS Region",
            "instanceType" : "d2.8xlarge",
            "currentGeneration" : "Yes",
            "instanceFamily" : "Storage optimized",
            "vcpu" : "36",
            "physicalProcessor" : "Intel Xeon E5-2676v3 (Haswell)",
            "clockSpeed" : "2.4 GHz",
            "memory" : "244 GiB",
            "storage" : "24 x 2000 HDD",
            "networkPerformance" : "10 Gigabit",
            "processorArchitecture" : "64-bit",
            "tenancy" : "Host",
            "operatingSystem" : "Linux",
            "licenseModel" : "No License required",
            "usagetype" : "HostBoxUsage:d2.8xlarge",
            "operation" : "RunInstances",
            "enhancedNetworkingSupported" : "Yes",
            "preInstalledSw" : "NA",
            "processorFeatures" : "Intel AVX; Intel AVX2; Intel Turbo" }
        }
    }   
}

当我尝试“PUT http://localhost:9200/aws”时,这是来自 ES 的返回响应

{ "error": {
"root_cause": [
  {
    "type": "illegal_argument_exception",
    "reason": "unknown setting [index.products.232CDFDW89ENUXRB.attributes.clockSpeed] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
  }
],
"type": "illegal_argument_exception",
"reason": "unknown setting [index.products.232CDFDW89ENUXRB.attributes.clockSpeed] please check that any required plugins are installed, or check the breaking changes documentation for removed settings" }, "status": 400 }

在我看来 ES 认为“clockSpeed”是某种设置......? 我希望使用动态映射来加快进程,而不是先映射所有文档,然后将其导入 ES。
有什么建议吗?

【问题讨论】:

    标签: elasticsearch illegalargumentexception


    【解决方案1】:

    问题是您在通过PUT http://localhost:9200/aws 命令索引文档时缺少document typedocument id

    索引文档的正确方法是:

    POST my-index/my-type/my-id-1
    {
      "name": "kibana"
    }
    

    即您必须提供 document type(此处为 my-type)和 document id(此处为 my-id-1)。请注意,此处的文档 ID 是可选的,因此如果您不提供,则 elasticsearch 会为您创建一个字母数字 ID。

    索引文档的其他几种方法:

    POST my-index/my-type
    {
      "name": "kibana"
    }
    
    //if you want to index document through PUT then you must provide document id
    PUT my-index/my-type/my-id-1
    {
      "name": "kibana"
    }
    

    注意:如果禁用自动创建索引,那么您必须在索引文档之前创建索引。

    【讨论】:

    • 如果以上答案解决了您的问题,那么您可以通过接受它作为答案来关闭问题。
    【解决方案2】:

    鉴于一个干净的映射,XPOST 在 elasticsearch 5.1.1 上非常适合我。

    $ curl -XPOST localhost:9200/productsapp/productdocs -d '
    {   "products" : {
         "sku1" : {
             "sku" : "SKU-Name",
             "productFamily" : "Compute Instance",
             "attributes" : {
                 "servicecode" : "AmazonEC2",
                 "location" : "US East (N. Virginia)",
                 "locationType" : "AWS Region",
                 "instanceType" : "d2.8xlarge",
                 "currentGeneration" : "Yes",
                 "instanceFamily" : "Storage optimized",
                 "vcpu" : "36",
                 "physicalProcessor" : "Intel Xeon E5-2676v3 (Haswell)",
                 "clockSpeed" : "2.4 GHz",
                 "memory" : "244 GiB",
                 "storage" : "24 x 2000 HDD",
                 "networkPerformance" : "10 Gigabit",
                 "processorArchitecture" : "64-bit",
                 "tenancy" : "Host",
                 "operatingSystem" : "Linux",
                 "licenseModel" : "No License required",
                 "usagetype" : "HostBoxUsage:d2.8xlarge",
                 "operation" : "RunInstances",
                 "enhancedNetworkingSupported" : "Yes",
                 "preInstalledSw" : "NA",
                 "processorFeatures" : "Intel AVX; Intel AVX2; Intel Turbo" }
             }
         }   
     }'
    {"_index":"productsapp","_type":"productdocs","_id":"AVuhXdYYUiSguAb0FsSX","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"created":true}
    

    GET插入的文档

    curl -XGET localhost:9200/productsapp/productdocs/_search
    {"took":11,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":1.0,"hits":[{"_index":"productsapp","_type":"productdocs","_id":"AVuhXdYYUiSguAb0FsSX","_score":1.0,"_source":{   "products" : {
        "sku1" : {
            "sku" : "SKU-Name",
            "productFamily" : "Compute Instance",
            "attributes" : {
                "servicecode" : "AmazonEC2",
                "location" : "US East (N. Virginia)",
                "locationType" : "AWS Region",
                "instanceType" : "d2.8xlarge",
                "currentGeneration" : "Yes",
                "instanceFamily" : "Storage optimized",
                "vcpu" : "36",
                "physicalProcessor" : "Intel Xeon E5-2676v3 (Haswell)",
                "clockSpeed" : "2.4 GHz",
                "memory" : "244 GiB",
                "storage" : "24 x 2000 HDD",
                "networkPerformance" : "10 Gigabit",
                "processorArchitecture" : "64-bit",
                "tenancy" : "Host",
                "operatingSystem" : "Linux",
                "licenseModel" : "No License required",
                "usagetype" : "HostBoxUsage:d2.8xlarge",
                "operation" : "RunInstances",
                "enhancedNetworkingSupported" : "Yes",
                "preInstalledSw" : "NA",
                "processorFeatures" : "Intel AVX; Intel AVX2; Intel Turbo" }
            }
        }   
    }}]}}
    

    它创建的映射如下,clockSpeedtext类型。

    curl -XGET localhost:9200/productsapp/productdocs/_mapping?pretty=true
    {
      "productsapp" : {
        "mappings" : {
          "productdocs" : {
            "properties" : {
              "products" : {
                "properties" : {
                  "232CDFDW89ENUXRB" : {
                    "properties" : {
                      "attributes" : {
                        "properties" : {
                          "clockSpeed" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "currentGeneration" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "enhancedNetworkingSupported" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "instanceFamily" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "instanceType" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "licenseModel" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "location" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "locationType" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "memory" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "networkPerformance" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "operatingSystem" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "operation" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "physicalProcessor" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "preInstalledSw" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "processorArchitecture" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "processorFeatures" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "servicecode" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "storage" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "tenancy" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "usagetype" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          },
                          "vcpu" : {
                            "type" : "text",
                            "fields" : {
                              "keyword" : {
                                "type" : "keyword",
                                "ignore_above" : 256
                              }
                            }
                          }
                        }
                      },
                      "productFamily" : {
                        "type" : "text",
                        "fields" : {
                          "keyword" : {
                            "type" : "keyword",
                            "ignore_above" : 256
                          }
                        }
                      },
                      "sku" : {
                        "type" : "text",
                        "fields" : {
                          "keyword" : {
                            "type" : "keyword",
                            "ignore_above" : 256
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    

    你能检查一下attributes.clockSpeed 的映射并确保它没有搞砸。

    如果您想更新文档,请在第一个文档的 id 上执行XPUT(即AVuhXdYYUiSguAb0FsSX),

    在以下示例中,我将 sku 字段更新为 "sku name updated"

    curl -XPUT localhost:9200/productsapp/productdocs/AVuhXdYYUiSguAb0FsSX -d '
    {
              "products" : {
                "sku1" : {
                  "sku" : "sku name updated",
                  "productFamily" : "Compute Instance",
                  "attributes" : {
                    "servicecode" : "AmazonEC2",
                    "location" : "US East (N. Virginia)",
                    "locationType" : "AWS Region",
                    "instanceType" : "d2.8xlarge",
                    "currentGeneration" : "Yes",
                    "instanceFamily" : "Storage optimized",
                    "vcpu" : "36",
                    "physicalProcessor" : "Intel Xeon E5-2676v3 (Haswell)",
                    "clockSpeed" : "2.4 GHz",
                    "memory" : "244 GiB",
                    "storage" : "24 x 2000 HDD",
                    "networkPerformance" : "10 Gigabit",
                    "processorArchitecture" : "64-bit",
                    "tenancy" : "Host",
                    "operatingSystem" : "Linux",
                    "licenseModel" : "No License required",
                    "usagetype" : "HostBoxUsage:d2.8xlarge",
                    "operation" : "RunInstances",
                    "enhancedNetworkingSupported" : "Yes",
                    "preInstalledSw" : "NA",
                    "processorFeatures" : "Intel AVX; Intel AVX2; Intel Turbo"
                  }
                }
              }}'
    {"_index":"productsapp","_type":"productdocs","_id":"AVu5OLfHPw6Pv_3O38-V","_version":2,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"created":false}
    

    【讨论】:

    • 我试过你的方法,它工作正常。映射也可以。请问你是怎么得到答案的?
    • 我不确定您是如何插入的?我仍然建议您去检查您遇到错误的类型的时钟速度映射是什么。
    • 和你一样,只是指定了索引: curl -XPOST localhost:9200/aws -d '{ ~~ }'
    • 所以你先创建了索引?否则你会得到No handler found for uri [/aws] and method [POST]?
    • 不,我在请求中指定了索引,但之前没有创建它,但我没有收到您发布的错误
    猜你喜欢
    • 2020-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多