Skip to content

mget API - document the support for fields parameter in URL, add support for fields parameter in request body #4006

Closed
@apidruchny

Description

The documentation for mget API only specifies that the fields parameter can be specified per document to get. But I tried and am using the un-documented feature of specifying the fields parameter in the URL. It would be good to make it a documented feature. It would also be good to support the fields parameter in the request body, as a top-level element. The motivation is that there is a limit on the URL size (4K as far as I remember) and a big field list may hit the limit. I had this problem in practice. It is also not best to repeat the same big field list for each document to get, and actually impossible at all if the ids element is used. Please see the reproduction below:

curl -XDELETE "http://localhost:9200/test/"; echo
curl -XPUT "http://localhost:9200/test/" -d'{
   "settings": {
      "number_of_replicas": 0,
      "number_of_shards": 5
   }
}'; echo

curl -XPUT 'http://localhost:9200/test/order/1-1' -d '{
   "productName":"doc 1",
   "quantity":1
}'; echo
curl -XPUT 'http://localhost:9200/test/order/1-2' -d '{
   "productName":"doc 2",
   "quantity":20
}'; echo
curl -XPUT 'http://localhost:9200/test/order/1-3?refresh=true' -d '{
   "productName":"doc 3",
   "quantity":5
}'; echo

# This works, returns 3 docs with productName field only
curl -XPOST 'http://localhost:9200/test/order/_mget?pretty=true&fields=productName' -d '{
   "ids" : [ "1-1", "1-2", "1-3" ]
}'; echo

# Fields parameter is ignored. This returns 3 docs with _source field
curl -XPOST 'http://localhost:9200/test/order/_mget?pretty=true' -d '{
   "fields" : [ "productName" ],
   "ids" : [ "1-1", "1-2", "1-3" ]
}'; echo

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions