elastic / elasticsearch-php

Official PHP client for Elasticsearch.
https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/index.html
MIT License
35 stars 970 forks source link

update with bulk support #452

Closed vus520 closed 8 years ago

vus520 commented 8 years ago

This client has bulk update support?

polyfractal commented 8 years ago

Yes, it uses the same bulk endpoint as used for indexing. Just use an 'update' => [] action instead of 'index' => [] action.

Docs here may help with some of the syntax: https://www.elastic.co/guide/en/elasticsearch/client/php-api/2.0/_indexing_documents.html#_bulk_indexing

vus520 commented 8 years ago

Awsome

ghost commented 6 years ago

doesnt work.

{"error":{"root_cause":[{"type":"action_request_validation_exception","reason":"Validation Failed: 1: script or doc is missing;"}],"type":"action_request_validation_exception","reason":"Validation Failed: 1: script or doc is missing;"},"status":400}

polyfractal commented 6 years ago

@rawmaterials you'll need to provide more information if you want help. And it would probably be easier to open a new ticket with the relevant info, instead of this closed ticket.

The exception basically says the problem: you need to provide a script or document to update with.

formigone commented 6 years ago

I'm facing the exact same issue. Here's my input to Elasticsearch\Client::bulk

Array
(
    [body] => Array
        (
            [0] => Array
                (
                    [update] => Array
                        (
                            [_index] => targeting
                            [_type] => sms
                            [_id] => 175523732
                        )

                )

            [1] => Array
                (
                    [name] => Local/hose-tubing/
                    [sf_product_family_id] =>
                    [enabled] =>
                    [table] => dfp_ad_units
                )
        )
)

Which throws with

{
  "error": {
    "root_cause": [
      {
        "type": "action_request_validation_exception",
        "reason": "Validation Failed: 1: script or doc is missing;"
      }
    ],
    "type": "action_request_validation_exception",
    "reason": "Validation Failed: 1: script or doc is missing;"
  },
  "status": 400
}
polyfractal commented 6 years ago

@formigone see my comment here: https://github.com/elastic/elasticsearch-php/issues/784#issuecomment-405715045 You need to specify a doc value in the body

formigone commented 6 years ago

Nice. Thanks for the prompt reply. However, since I am just getting started with ElasticSearch, do you mind helping me see what else I'm missing? Adding a doc returns the following error:

Array
(
    [took] => 268
    [errors] => 1
    [items] => Array
        (
            [0] => Array
                (
                    [update] => Array
                        (
                            [_index] => targeting
                            [_type] => sms
                            [_id] => 175523732
                            [status] => 404
                            [error] => Array
                                (
                                    [type] => document_missing_exception
                                    [reason] => [sms][175523732]: document missing
                                    [index_uuid] => WdORQ2AnSAyVI8SZ-KxC2g
                                    [shard] => 1
                                    [index] => targeting
                                )
                        )
                )
        )
)

Here's what ElasticSearch returns when I query it with http://localhost:9200/targeting/_search?q=hose-tubing

{
  "took": 2,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 6,
    "max_score": 22.095295,
    "hits": [
        {
            "_index": "targeting",
            "_type": "sms",
            "_id": "175523732",
            "_score": 22.095295,
            "_source": {
                "name": "Local/hose-tubing",
                "sf_product_family_id": null,
                "enabled": false,
                "table": "dfp_ad_units"
            }
         },

My input into client->bulk():

Array
(
    [body] => Array
        (
            [0] => Array
                (
                    [update] => Array
                        (
                            [_index] => targeting
                            [_type] => sms
                            [_id] => 175523732
                        )
                )

            [1] => Array
                (
                    [doc] => Array
                        (
                            [name] => If you see me, then I was updated!
                            [sf_product_family_id] =>
                            [enabled] =>
                            [table] => dfp_ad_units
                        )
                )
        )
)

Thanks again =)

polyfractal commented 6 years ago

@formigone I have no idea to be honest. Can you confirm the PHP client and the browser query are hitting the same cluster? Are there any issues in the cluster (red cluster stats, missing shards, split brain etc)?