Я использую последнюю версию Elasticsearch на Ubuntu 16.04, и у меня возникла небольшая проблема с размещением данных на нем.

Вот мой документ 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.
Любое предложение?

2
Emanuele Leopardi 24 Апр 2017 в 22:02

2 ответа

Лучший ответ

Проблема в том, что вы упускаете document type и document id при индексации документа с помощью команды PUT http://localhost:9200/aws.

Правильный способ индексирования документа:

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

Т.е. вы должны предоставить document type (здесь my-type) и document id (здесь my-id-1). Обратите внимание, что идентификатор документа здесь не обязателен, поэтому, если вы его не предоставите, elasticsearch создаст для вас один буквенно-цифровой идентификатор.

Другая пара способов индексирования документа:

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
avr 24 Апр 2017 в 20:36

Учитывая чистое сопоставление, XPOST отлично работает для меня вasticsearch 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" }
        }
    }   
}}]}}

Это отображение, как показано ниже, с 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),

В следующем примере я обновляю поле 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
prayagupd 29 Апр 2017 в 10:30