ElasticSearch非法参数异常

时间:2017-04-24 19:02:20

标签: elasticsearch illegalargumentexception

我在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中导入它 有什么建议吗?

2 个答案:

答案 0 :(得分:2)

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

索引文档的正确方法是:

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

即您必须提供document type(此处为my-type)和document id(此处为my-id-1)。请注意,文档ID在此处是可选的,因此如果您不提供,则弹性搜索会为您创建一个字母数字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"
}

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

答案 1 :(得分:0)

鉴于清晰的映射,XPOST在弹性搜索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}