elastic / elasticsearch-php

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

What is query check exist document? #485

Closed hatienkma closed 7 years ago

hatienkma commented 7 years ago

I want to check exist document before index new document.

I use search param but it not success.

$params = [ 'index' => $indexDB, 'type' => $typeDB, 'body' => [ 'query' => [ 'match' => [ 'email' => $email ] ] ]

];

Any one can recommend query check exists documents?

System details

dcarbone commented 7 years ago

https://github.com/elastic/elasticsearch-php/blob/v2.2.2/src/Elasticsearch/Namespaces/IndicesNamespace.php#L31 is probably what you want.

$exists = $client->indices()->exists(['index' => 'your-index-name']);
polyfractal commented 7 years ago

Do you know the documents ID? You can use the Exists API if you know the index/type/id of a doc.

polyfractal commented 7 years ago

Oops, just saw @dcarbone reply. Note: that method ($client->indices()->exists([...])) is for determining if an entire index exists, where as the other exists ($client->exists([...])) is for checking individual documents

dcarbone commented 7 years ago

Ah, thanks for the clarification :)

polyfractal commented 7 years ago

Closing, @hatienkma feel free to reopen if you need more help :)

syiand commented 6 years ago

I am trying the achieve the same functionality with a different way. Can you please take a look and give me a hint what changes I should make? Here is the post.