ElasticSearch Illegal Argument Exception

て烟熏妆下的殇ゞ 提交于 2020-01-13 06:15:42

问题


I'm using Elasticsearch latest version on Ubuntu 16.04 and I'm having a little issue on putting data on it.

here is my json document (relevant part of it)

{   "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" }
        }
    }   
}

and here's the returning response from ES when i try "PUT http://localhost:9200/aws"

{ "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 }

Seems to me ES thinks that "clockSpeed" is some sort of setting...? I was hoping to use dynamic mapping to speed the process up instead of first mapping all the document and then importing it in ES.
Any suggestion?


回答1:


The issue is you are missing document type and document id while indexing a document through PUT http://localhost:9200/aws command.

Proper way to index document is:

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

i.e You have to provide document type (here my-type) and document id (here my-id-1). Note that document id is optional here so if you don't provide one then elasticsearch create one alphanumeric id for you.

Other couple of ways indexing a doc:

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"
}

Note: If automatic index creation is disabled then you have to create index before indexing documents.




回答2:


Given a clean mapping, XPOST works perfectly for me on 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 the inserted doc

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" }
        }
    }   
}}]}}

The mapping it creates is as below, with clockSpeed as text type.

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
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Can you check you mapping for attributes.clockSpeed and make sure its not screwed up.

And if you want to update the document do XPUT on the id of first document (which is AVuhXdYYUiSguAb0FsSX),

In following example, I am updating sku field to "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}


来源:https://stackoverflow.com/questions/43595853/elasticsearch-illegal-argument-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!