Unable to find document on _id in elasticsearch mongodb


(Satyadeep Kumar) #1

I am trying to lookup a mongodb document based on its _id in elasticsearch using php-2.0 api of elasticsearch. It is giving me error

[2016-03-22 01:38:34,672][DEBUG][action.search.type       ] [Cameron Hodge] [smartjn][1], node[rMZbhVr7R-ezCeg2DeirLQ], [P], v[4], s[STARTED], a[id=q1AbfdiHTN6RqA2p_DTw8g]: Failed to execute [org.elasticsearch.action.search.SearchRequest@55c6bb7d] lastShard [true]
RemoteTransportException[[Cameron Hodge][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: SearchParseException[failed to parse search source [{"query":{"match":{"uid":{}}}}]]; nested: QueryParsingException[No text specified for text query];
Caused by: SearchParseException[failed to parse search source [{"query":{"match":{"uid":{}}}}]]; nested: QueryParsingException[No text specified for text query];

The code is

require 'vendor/autoload.php';
$userId = new MongoDB\BSON\ObjectId($userID);

$client2 = Elasticsearch\ClientBuilder::create()->build();
                       $params = [
    'index' => 'smartjn',
    'type' => 'user_master',
    'body' => [
        'query' => [
                'match' => ['_id' => $userId]
                  ]
              ]
        ];
$results2 = $client2->search($params);

Any pointers on what am I doing wrong?

Thanks


(Mark Walkom) #2

I don't know PHP, but it doesn't look like your ID is being passed in.


(Satyadeep Kumar) #3

Hi @warkolm , sorry I pasted an old log , the recent one is

[2016-03-22 03:32:33,483][DEBUG][action.search.type       ] [Cameron Hodge] [smartjn][1], node[rMZbhVr7R-ezCeg2DeirLQ], [P], v[4], s[STARTED], a[id=q1AbfdiHTN6RqA2p_DTw8g]: Failed to execute [org.elasticsearch.action.search.SearchRequest@2b7ced36] lastShard [true]
RemoteTransportException[[Cameron Hodge][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: SearchParseException[failed to parse search source [{"query":{"match":{"_id":{}}}}]]; nested: QueryParsingException[No text specified for text query];
Caused by: SearchParseException[failed to parse search source [{"query":{"match":{"_id":{}}}}]]; nested: QueryParsingException[No text specified for text query];

Thanks


(Mark Walkom) #4

It's still the same error.


(Satyadeep Kumar) #5

Yes the error is same, and I am trying to understand the error behind it , and how to rectify it.

Thanks


(Mark Walkom) #6

Like I said, your ID isn't being passed to ES in the query, so I'd start by making sure your code does that.


(Satyadeep Kumar) #7

silly mistake from my side , just passed the id as String without converting it to BSON object.

Thank you all.


(system) #8