Update a mongodb document using elasticsearch php

Hi,

I am trying to update a document based on _id of the document using the following code:

require_once 'vendor/autoload.php';

    $client = Elasticsearch\ClientBuilder::create()->build();
    $params = [
        'index' => 'smartjn',
        'type' => 'user_master',
        'body' => [
            'query'=> [
                    'match'=> [
                                    'accessToken' => $accessToken
                    ]
            ]
        ]
       ];
    $results = $client->search($params);
    $result = $results['hits']['hits'][0]['_id'];

    $params = [
        'index' => 'smartjn',
        'type' => 'user_master',
        'body' => [
                             'update' => [
                                            '_id' => $result
                                          ]
                            ,
             'doc' => [
                'deviceId' => $deviceId
            ]
        ]
    ];
    $response = $client->update($params);
    var_dump($response);

The code is giving error on the $client->update() line . I am failing to understand the problem, any help will be greatly appreciated.

Thanks

Any one , any help?

Thanks

Please be patient when waiting for an answer to your questions. This is a community forum and as such it may take some time before someone replies to your question. Not everyone on the forum is an expert in every area so you may need to wait for someone who knows about the area you are asking about to come online and have the time to look into your problem.

Please see https://www.elastic.co/community/codeofconduct for more details on our code of conduct (in particular the "be patient" section).

There are no SLAs on responses to questions posted on this forum, if you require help with an SLA on responses you should look into purchasing a subscription package that includes support with an SLA such as those offered by Elastic: https://www.elastic.co/subscriptions

By the way, you will get more chance of having someone answering if:

  • you format your code. There is a button for that. </>
  • you describe with more details what is happening. For example The code is giving error is very vague.

mea culpa @dadoonet .

Please accept apologies for the same.

Thanks

No problem. But can you reformat your code please?

just did it. Thanks

What is the error you are getting? Can you reproduce this without PHP but with a pure REST script so more people could help? (I'm not a PHP guy :slight_smile: )

Anyone any help ? Was wondering whether I am going in right direction?

Thanks

Nothing in yet :frowning: . Any help is greatly appreciated.

Thanks

I'm just going to copy and paste the same questions I asked.

What is the error you are getting? Can you reproduce this without PHP but with a pure REST script so more people could help?

I do not see an error in elasticsearch as well as mongodb logs.

I can not reproduce the same bug using pure REST script as of now.

Thanks

So there is no error with elasticsearch.
You don't see any error in elasticsearch or mongodb.

But you wrote that:

The code is giving error on the $client->update() line.

So from where your error is coming from?

I'm sorry but we can't help without knowing what you are doing and what is exactly your problem.