2017-04-24 130 views
1

我在Ubuntu 16.04上使用Elasticsearch最新版本,我在将数据放在它上面时遇到了一些小问题。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" } 
     } 
    } 
} 

,这里是从ES返回的响应,当我尝试 “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 } 

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

回答

0

问题是,您在丢失document typedocument id的同时通过PUT http://localhost:9200/aws命令索引文档。

有道索引文件是:

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

即你必须提供document type(这里我型)和document id(这里我-ID-1)。请注意,文档ID在此处是可选的,所以如果您不提供文档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" 
} 

注:如果自动创建索引被禁用,那么你必须创建索引文件之前指数。

+0

我明白了,谢谢你的帮助! –

+0

如果上述答案解决了您的问题,那么您可以通过接受答案来解决问题。 – avr

0

给定一个干净的映射,XPOST完全适合我在elasticsearch 5.1.1上。

​​

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

它创建是在如下状态,与作为clockSpeed类型text的映射。

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,并确保其不会搞砸了。

如果你想更新文档做XPUT在头文件(这是AVuhXdYYUiSguAb0FsSX)的ID,

在下面的例子中,我更新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} 
+0

我试过你的方式,它的工作正常。此外,映射也没关系。 我可以问你,你是如何得到答案的? –

+0

我不确定你是如何插入的?我仍然建议去检查clockSpeed的映射是什么类型的错误。 – prayagupd

+0

与您所做的相同,只是指定了索引:curl -XPOST http:// localhost:9200/aws/-d'{~~}' –