Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to request a single document by _id via alias?

Is it possible to request a single document by its id by querying an alias, provided that all keys across all indices in the alias are unique (it is an external guarantee)?

like image 255
Mischa Arefiev Avatar asked Mar 12 '15 11:03

Mischa Arefiev


People also ask

What should you use to fetch a document in Elasticsearch?

You use GET to retrieve a document and its source or stored fields from a particular index. Use HEAD to verify that a document exists. You can use the _source resource retrieve just the document source or verify that it exists.

How do I list documents in an index Elasticsearch?

Elasticsearch will get significant slower if you just add some big number as size, one method to use to get all documents is using scan and scroll ids. The results from this would contain a _scroll_id which you have to query to get the next 100 chunk. This answer needs more updates. search_type=scan is now deprecated.

How is _id generated for Elasticsearch?

It is an URL-safe, Base64-encoded GUID generated using modified FlakeID algorithm. FlakeID is a decentralized algorithm that generates k-ordered unique IDs. Note that Elasticsearch does not generate the _id using the random UUIDs anymore.

Why this request is not getting the document with ID 2?

This request gets the document with id 2, but it is routed based on the user. The document is not fetched if the correct routing is not specified.

Is it possible to query an alias spanning over multiple indices?

Yes, querying an alias spanning over multiple indices work the same way as querying one indice. POST my_alias_name/_search { "filter": { "term": {"_id": "AUwNrOZsm6BwwrmnodbW"} } }

How to find a document with some internal ID with Curl?

In case you want to find a document with some internal id with curl: Following Elasticsearch 8.2 Doc, you can retrieve a single document by using GET API:


1 Answers

In case you want to find a document with some internal id with curl:

curl -X GET 'localhost:9200/_search?q=id:42&pretty'
like image 183
Aliaksei Avatar answered Sep 20 '22 14:09

Aliaksei