在使用Nest(Elasticsearch)执行DeleteByQuery时,获取"已添加此项的项"

Jim*_*Jim 4 c# elasticsearch nest

我试图运行删除查询来删除索引中两个时间戳之间的文档,我得到一个非常奇怪的结果.

这是我的代码:

// how the index is created
if (!es.IndexExists(indexName).Exists)
{
    es.CreateIndex(descriptor => descriptor
        .Index(indexName)
        .AddMapping<MyDocument>(m => m
            .MapFromAttributes()));
}

// event object that is mapped
public class MyDocument
{
    public long Id { get; set; }

    public long EventTime { get; set; }

    [ElasticProperty(Index = FieldIndexOption.NotAnalyzed)]
    public string EventType { get; set; }

    public DateTime CreatedAt { get; set; }

    public IDictionary<string, object> Values { get; set; }
    // snip
}

// delete call
IElasticClient es;
es.DeleteByQuery<MyDocument>(q => q
    .Query(rq => rq
        .Range(t => t.OnField("eventTime").GreaterOrEquals(startTimestamp).LowerOrEquals(endTimestamp)));
Run Code Online (Sandbox Code Playgroud)

这引发了一个异常,说"已经添加了一个具有相同键的项".这个删除查询会导致此异常,我做错了什么?

以下是我通过elasticsearch进行的搜索的示例文档:

{
  "took" : 8,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 96,
    "max_score" : 1.0,
    "hits" : [ {
      "_index" : "testing2",
      "_type" : "mydocument",
      "_id" : "112",
      "_score" : 1.0,
      "_source":{"id":112,"eventTime":12345690,"eventDate":"1970-05-23T17:21:30-04:00","eventTypeId":0,"ready":false,"name":"","doccount":0,"wordcount":0,"createdAt":"2015-06-25T09:29:33.8996707-04:00","values":{"internal_timestamp":76890.0},"childDocuments":[],"parentDocuments":[]}
    }, /* snip */]
  }
}
Run Code Online (Sandbox Code Playgroud)

Jim*_*Jim 14

Rob和我刚刚解决了这个问题.

这是发生在这里的问题是,我的项目使用Newtonsoft.Json的版本7.0.0与版本巢1.5.1,而鸟巢1.5.1要求6.0.1.这种不匹配导致查询序列化抛出异常.

这可以通过将Nest升级到版本1.6.1或降级Newtonsoft.Json到版本来解决6.0.1.