[英]Getting “An item with this key has already been added” when performing a DeleteByQuery with Nest (Elasticsearch)
I am trying to run a delete query to delete documents between two timestamps in an index, and I am getting a very strange result. 我试图运行删除查询来删除索引中两个时间戳之间的文档,我得到一个非常奇怪的结果。
Here is my code: 这是我的代码:
// 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)));
This throws an exception saying "An item with the same key has already been added". 这引发了一个异常,说“已经添加了一个具有相同键的项”。 What am I doing wrong with this delete query that would throw this exception?
这个删除查询会导致此异常,我做错了什么?
Here is a sample document from a search I did through elasticsearch: 以下是我通过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 */]
}
}
Rob and I just worked this out. Rob和我刚刚解决了这个问题。
The problem that was occurring here is that my project is using Newtonsoft.Json
version 7.0.0
with Nest version 1.5.1
, whereas Nest 1.5.1
requires 6.0.1
. 这里出现的问题是我的项目使用的是
Newtonsoft.Json
版本7.0.0
和Nest版本1.5.1
,而Nest 1.5.1
需要6.0.1
。 This mismatch was causing the serialization of queries to throw exceptions. 这种不匹配导致查询序列化抛出异常。
This can be solved by either upgrading Nest to version 1.6.1
or downgrading Newtonsoft.Json
to version 6.0.1
. 这可以通过将Nest升级到
1.6.1
版或将Newtonsoft.Json
降级到6.0.1
版来解决。
I've simply updated newtonsoft.json to latest version. 我刚刚将newtonsoft.json更新为最新版本。 My current version was 5.0.1, I've updated to 9.0.1.
我当前的版本是5.0.1,我已经更新到9.0.1。 After that, error went away.
在那之后,错误就消失了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.