перераспределение в один выходной файл на клиента

_id не является частью документа _source, а является частью метаданных попадания для каждого попадания в массив hits.

Самый компактный способ вернуть только поля _id будет с с использованием фильтрации ответа , которая отображается как FilterPath в NEST

private static void Main()
{
    var defaultIndex = "documents";
    var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));

    var settings = new ConnectionSettings(pool)
        .DefaultIndex(defaultIndex)
        .DefaultTypeName("_doc");

    var client = new ElasticClient(settings);

    if (client.IndexExists(defaultIndex).Exists)
        client.DeleteIndex(defaultIndex);

    client.Bulk(b => b
        .IndexMany(new[] {
            new { Message = "hello" },
            new { Message = "world" }
        })
        .Refresh(Refresh.WaitFor)
    );

    var searchResponse = client.Search(new SearchRequest
    {
        From = 0 * 100,
        Size = 100,
        FilterPath = new [] { "hits.hits._id" },
        Query = new QueryStringQuery
        {
            Query = ""
        }
    });

    foreach(var id in searchResponse.Hits.Select(h => h.Id))
    {
        // do something with the ids
        Console.WriteLine(id);
    }
}

. Ответ JSON от Elasticsearch на запрос поиска выглядит как

{
  "hits" : {
    "hits" : [
      {
        "_id" : "6gs8lmQB_8sm1yFaJDlq"
      },
      {
        "_id" : "6Qs8lmQB_8sm1yFaJDlq"
      }
    ]
  }
}

1
задан Georg Heiler 19 January 2019 в 09:30
поделиться