ElasticSearch and Nest: Why am I missing the id field in the request?

I created a simple object representing a collection that has elements such as time, location, name, theme, etc., and indexed it in ElasticSearch via Nest. It has an Id field that I leave blank so the ES can generate them.

Later, I received all the documents that do not have the GEO coordinates, so that I can update them. All of my returned items are still null for the id field, and when I upgrade them to ES, it creates new documents for them.

What am I missing here, which makes my entire identifier null?

thanks

Here is the Meeting class (id prop is redundant, but I tried anyway)

[ElasticType(IdProperty = "Id")]
    public class Meeting
    {
        public string Id { get; set; }
        public string Code { get; set; }
        public string Day { get; set; }
        public string Town { get; set; }
        public string Name { get; set; }
        public string Location { get; set; }
        public string OriginalTime { get; set; }
        public string OriginalTimeCleaned { get; set; }
        public string Handicap { get; set; }
        public string FormattedAddress { get; set; }
        public Coordinates Coordinates { get; set; }
        public List<MeetingTime> Times = new List<MeetingTime>();
        public bool IsProcessed { get; set; }    
    }

This is how i get meetings

 public static List<Meeting> GetAddressesWithMissingCoordinates()
        {

            var result = Client.Search<Meeting>(s => s
                .Index("meetings")
                .AllTypes()
                .Query(p => p.Filtered(f => f.Filter(x => x.Missing(c => c.Coordinates)))));


            return result.Documents.ToList();
        }

Here is my update statement, Id is null

 public static void UpdateMeetingCoordinates(Meeting meeting, Coordinates coordinates)
        {
            meeting.Coordinates = coordinates;

            var response = Client.Index(meeting, u => u
                .Index("meetings")
                .Type("meeting")
                //.Id(meeting.Id.ToString())
                .Refresh()
                );

            Console.WriteLine(response);
        }

I also tried partial updates, but no luck.

+4
2

Elasticsearch "_id" ( , ), .

, :

PUT /test_index

, "_id":

POST /test_index/doc/_bulk
{"index":{}}
{"id":null,"name":"doc1"}
{"index":{}}
{"id":null,"name":"doc2"}

:

POST /test_index/_search

:

{
   "took": 2,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 2,
      "max_score": 1,
      "hits": [
         {
            "_index": "test_index",
            "_type": "doc",
            "_id": "AVEmuVlmj_RE0PsHCpza",
            "_score": 1,
            "_source": {
               "id": null,
               "name": "doc2"
            }
         },
         {
            "_index": "test_index",
            "_type": "doc",
            "_id": "AVEmuVlmj_RE0PsHCpzZ",
            "_score": 1,
            "_source": {
               "id": null,
               "name": "doc1"
            }
         }
      ]
   }
}

, "_id", "id", , . , Elasticsearch, "id" - .

( , : http://sense.qbox.io/gist/777dafae88311c4105453482050c64d69ccd09db)

+4

, .

response.Documents :

var results = response.Hits.Select(hit =>
    {
        var result = hit.Source;
        result.Id = hit.Id;
        return result;
    });
+4

Source: https://habr.com/ru/post/1616784/


All Articles