ElasticSearch and Nest:为什么我缺少一个查询的id字段? [英] ElasticSearch and Nest: Why amd I missing the id field on a query?

查看:213
本文介绍了ElasticSearch and Nest:为什么我缺少一个查询的id字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的对象,代表一个会议,它具有时间,位置,名称,主题等元素,并通过Nest在ElasticSearch中进行索引。它有一个Id字段,我留空,以便ES可以生成它们。

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

稍后我检索到所有缺少GEO坐标的文档,以便我可以更新它们。我所有返回的元素对于id字段仍然为空,当我将其更新回ES时,它会为它们创建新的文档。

Later on I retrieved all the documents that are missing GEO coordinates so that I may update them. All my returned elements still have null for the id field and when I update them back to ES it creates new documents for them.

我在这里缺少什么,使我的所有ID都为空?

What am I missing here that makes all my id's null?

谢谢

这是会议类(id支架是多余的,但是我也尝试过)

Here is the Meeting class (the id prop is redundant but I tried it 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; }    
    }

这是我如何检索会议

 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();
        }

这是我的更新语句,Id为null

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've tried partial updates as well with no luck.

推荐答案

Elasticsearch设置一个_ id元数据参数(为它选择一个价值,如果你没有指定一个),但它没有在您的文档来源设置该值

Elasticsearch sets an "_id" meta-data parameter (for which it chooses a value if you don't specify one), but it doesn't set that value in your document source.

为了说明,如果我创建一个平凡的索引:

To illustrate, if I create a trivial index:

PUT /test_index

然后给它一些文件,而不指定_ id

then give it a couple of documents, without specifying "_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字段没有改变。这是因为,就弹性搜索而言,id只是另一个文档字段。

Notice that the "_id" meta-data parameter was set for both documents, but the "id" field I passed is unchanged. That's because, as far as Elasticsearch is concerned, "id" is just another document field.

(这里是我使用的代码: http://sense.qbox.io/gist/777dafae88311c4105453482050c64d69ccd09db

(here is the code I used: http://sense.qbox.io/gist/777dafae88311c4105453482050c64d69ccd09db)

这篇关于ElasticSearch and Nest:为什么我缺少一个查询的id字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆