2

I am attempting to make use of multi get to return a collection of strongly typed objects with source filtering and although I have been able to create the result I want with the JSON API for ElasticSearch, I am not sure how to translate it into the NEST 1.0 API.

This is the query I am trying to produce; it works correctly:

GET index/thing/_mget 
{
    "docs" : [
        {
            "_id": "00000000-0000-0000-0000-000000000030",
            "_source": ["id", "name"]
        },
        {
            "_id": "00000000-0000-0000-0000-000000000321",
            "_source": ["id", "name"]
        }
        /* ....  */
    ]
}

This is what I've been toying with but it does not actually filter the sources; instead, it's returning the full object:

client.MultiGet(s => s
    .GetMany<Thing>(ids)
    .SourceEnabled("id", "name"))

Any help would be appreciated. Also, it would be preferable to use a signature for the SourceEnabled() call which is expression based (type safe), if one exists.

Nathan Taylor
  • 24,423
  • 19
  • 99
  • 156

1 Answers1

3

Looks like this is a bug. I just opened issue #849 on GitHub to address this.

In the meantime, specifying fields serves a similar purpose and might be a workaround for you:

var result = client.MultiGet(s => s
    .GetMany<Thing>(ids, (d, i) => d.Fields("id", "name"))
);

var fieldSelection = result.GetFieldSelection<Person>(1);
var fields = fieldSelection.FieldValues<string>("name");
Greg Marzouka
  • 3,315
  • 1
  • 20
  • 17