2017-04-24 85 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'{~~}' –