Elasticsearch: get multiple specified documents in one request?

curious1

I am new to Elasticsearch and hope to know whether this is possible.

Basically, I have the values in the "code" property for multiple documents. Each document has a unique value in this property. Now I have the codes of multiple documents and hope to retrieve them in one request by supplying multiple codes.

Is this doable in Elasticsearch?

Regards.

Edit

This is the mapping of the field:

"code" : { "type" : "string", "store": "yes", "index": "not_analyzed"},

Two example values of this property:

0Qr7EjzE943Q
GsPVbMMbVr4s

What is the ES syntax to retrieve the two documents in ONE request?

Sloan Ahrens

First, you probably don't want "store":"yes" in your mapping, unless you have _source disabled (see this post).

So, I created a simple index like this:

PUT /test_index
{
   "mappings": {
      "doc": {
         "properties": {
            "code": {
               "type": "string",
               "index": "not_analyzed"
            }
         }
      }
   }
}

added the two docs with the bulk API:

POST /test_index/_bulk
{"index":{"_index":"test_index","_type":"doc","_id":1}}
{"code":"0Qr7EjzE943Q"}
{"index":{"_index":"test_index","_type":"doc","_id":2}}
{"code":"GsPVbMMbVr4s"}

There are a number of ways I could retrieve those two documents. The most straightforward, especially since the field isn't analyzed, is probably a with terms query:

POST /test_index/_search
{
    "query": {
        "terms": {
           "code": [
              "0Qr7EjzE943Q",
              "GsPVbMMbVr4s"
           ]
        }
    }
}

both documents are returned:

{
   "took": 21,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 2,
      "max_score": 0.04500804,
      "hits": [
         {
            "_index": "test_index",
            "_type": "doc",
            "_id": "1",
            "_score": 0.04500804,
            "_source": {
               "code": "0Qr7EjzE943Q"
            }
         },
         {
            "_index": "test_index",
            "_type": "doc",
            "_id": "2",
            "_score": 0.04500804,
            "_source": {
               "code": "GsPVbMMbVr4s"
            }
         }
      ]
   }
}

Here is the code I used:

http://sense.qbox.io/gist/a3e3e4f05753268086a530b06148c4552bfce324

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Elasticsearch get the latest documents, grouped by multiple fields

From Dev

Insert multiple documents in elasticsearch

From Dev

Elasticsearch: get all documents where array contains one of many values

From Dev

Matching across Multiple documents with ElasticSearch

From Dev

Elasticsearch GET request with request body

From Dev

ElasticSearch: Finding documents with multiple identical fields

From Dev

How to update multiple documents that match a query in elasticsearch

From Dev

ElasticSearch: Finding documents with multiple identical fields

From Dev

How to return multiple Mongoose collections in one get request?

From Dev

How to return multiple Mongoose collections in one get request?

From Dev

Facebook Graph API get comment count for multiple urls in one request

From Dev

Elasticsearch - How to get popular words list of documents

From Dev

Elasticsearch Get the values of a field from all the documents

From Dev

Get all documents from ElasticSearch using elasticsearchTemplate

From Dev

Elastic - updating multiple documents in a single request

From Dev

MongoDB query for documents that contain at least one of the values specified in an array

From Dev

Elasticsearch - get terms aggregation for specified fields

From Dev

Elasticsearch: Get distinct record by a specified field

From Dev

How to get only specified values record from multiple values of one Record in sql server

From Dev

How to get only specified values record from multiple values of one Record in sql server

From Dev

How to replace multiple documents in one DB call

From Dev

Combine multiple lines of text documents into one

From Dev

One query to search in multiple types documents

From Dev

Process to big for one request, when splitted in multiple request too the same page i get redirect loop

From Dev

Mongodb : Get Documents between specified time irrespective of dates

From Dev

Mongo Get all the documents within 10 miles of location specified

From Dev

How to delete several documents by ID in one operation using Elasticsearch Nest

From Dev

how to copy one index documents to other index in elasticsearch?

From Dev

What are the pros and cons of loading an angular page with multiple get requests instead of one get request?

Related Related

  1. 1

    Elasticsearch get the latest documents, grouped by multiple fields

  2. 2

    Insert multiple documents in elasticsearch

  3. 3

    Elasticsearch: get all documents where array contains one of many values

  4. 4

    Matching across Multiple documents with ElasticSearch

  5. 5

    Elasticsearch GET request with request body

  6. 6

    ElasticSearch: Finding documents with multiple identical fields

  7. 7

    How to update multiple documents that match a query in elasticsearch

  8. 8

    ElasticSearch: Finding documents with multiple identical fields

  9. 9

    How to return multiple Mongoose collections in one get request?

  10. 10

    How to return multiple Mongoose collections in one get request?

  11. 11

    Facebook Graph API get comment count for multiple urls in one request

  12. 12

    Elasticsearch - How to get popular words list of documents

  13. 13

    Elasticsearch Get the values of a field from all the documents

  14. 14

    Get all documents from ElasticSearch using elasticsearchTemplate

  15. 15

    Elastic - updating multiple documents in a single request

  16. 16

    MongoDB query for documents that contain at least one of the values specified in an array

  17. 17

    Elasticsearch - get terms aggregation for specified fields

  18. 18

    Elasticsearch: Get distinct record by a specified field

  19. 19

    How to get only specified values record from multiple values of one Record in sql server

  20. 20

    How to get only specified values record from multiple values of one Record in sql server

  21. 21

    How to replace multiple documents in one DB call

  22. 22

    Combine multiple lines of text documents into one

  23. 23

    One query to search in multiple types documents

  24. 24

    Process to big for one request, when splitted in multiple request too the same page i get redirect loop

  25. 25

    Mongodb : Get Documents between specified time irrespective of dates

  26. 26

    Mongo Get all the documents within 10 miles of location specified

  27. 27

    How to delete several documents by ID in one operation using Elasticsearch Nest

  28. 28

    how to copy one index documents to other index in elasticsearch?

  29. 29

    What are the pros and cons of loading an angular page with multiple get requests instead of one get request?

HotTag

Archive