简体   繁体   中英

Is it possible to map Elastic document ID value to a field in your mapping

I know its possible to map your personal id so that the document id would be the same as your personal id, but is it possible to have it other way around ?

How to map document id value to a property in your mapping ?

Answers could be preferably using C# NEST library but not necessary, thank you.

I'm not aware of any feature that can modify the source that is indexed into ES.

The (deprecated) transform feature could add a new arbitrary field at indexing time, but would not modify the source, which means that when retrieving the results, you'd not get the created field.

I'd suggest you create your own IDs and assign them to your MyDocId field and don't let ES generate them.

Note that in ES 5, we'll have a new type of node called Ingest node , which will allow to define transformation pipelines, similar to what can be done with Logstash filters. At that point, you'll be able to use the set processor in order to set/create an arbitrary field and achieve what you want:

{
  "set": {
    "field": "MyDocId",
    "value": "_id"
  }
}

NEST won't currently map a generated id onto a property of a POCO; you can assign the id manually from response.Hits metadata using

var response = client.Search<Poco>();

var pocos = response.Hits.Select(hit =>
    {
        hit.Source.Id = h.Id;
        return hit.Source;
    }).ToList();

This was discussed again in January and we decided to keep the current implementation; the POCO maps to the _source in Elasticsearch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM