"Key was already exists" on NEST indexing after upgrading from ES v6.8.1
See original GitHub issueNEST/Elasticsearch.Net version: 7.2.0/7.2.0 (and 7.1.0/7.1.0)
Elasticsearch version: 7.3.0
Description of the problem including expected versus actual behavior:
I upgraded my elasticsearch server from 6.8.1 to 7.3.0 and after this, the NEST indexing function (Client.IndexDocument(document)
) throws with Key was already exists. Key:MultipleChoices
. I can’t see any properties in my document corresponding to “MultipleChoices”, so I’m not sure where that is coming from.
Furthermore, by changing what index it posts to, I still get the same error (even on a new index), and the (new) index is never created, so this error gets thrown before indexing happens.
If I change the document type from my custom class to just new
-ing up a { Test = "testing" }
, that indexes successfully without throwing an error.
Simply POSTing the document directly at the Elasticsearch API also works fine.
By rewriting my code to use the low-level client I made it work again:
Client.LowLevel.Index<MyType>(index, documentAsJson);
I searched a bit and found #3706, but that looks a lot more low-level than what I was doing, but maybe that error propagates up to the NEST index function? It is the case that my custom type was first created/indexed on ES v6.6.0, then used again on v6.8.1 and now in v7.3.0.
My custom class is as follows:
[Serializable] // using Elasticsearch.Net;
public class HealthCheckResponse : IElasticsearchResponse
{
// HealthStatus, HealthCheckProtocol and HttpStatusCode are enums
public string Host;
public HealthStatus Status;
public string Message;
public string Name;
public HealthCheckProtocol Protocol;
public DateTime Timestamp;
public HttpStatusCode HttpStatusCode;
public long PingRoundTripTime;
}
And the JSON I now send “manually” through the low-level client API is as follows (manually mapping the enums from ints to strings)
{
"host": "127.0.0.1",
"status": "Success",
"message": "Success",
"name": "localhost",
"protocol": "Ping",
"timestamp": "2019-08-16T13:33:21.8036015+02:00",
"httpStatusCode": 0,
"pingRoundTripTime": 0
}
Steps to reproduce:
- Use NEST.Client.IndexDocument to index a document against an ES v6.6.0 server
- Upgrade the ES server to v7.3.0 (through 6.8.1)
- Try to use IndexDocument the same way against the upgraded server, and get an exception thrown.
Do tell if you would like me to debug some more or test some other cases, I’ll do my best to help out debugging this 😃 And feel free to ask for more information if that’s relevant.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (6 by maintainers)
Top GitHub Comments
A friend of mine noticed this pull request to the original Utf8Json library which targets an issue with the same exception message. https://github.com/neuecc/Utf8Json/issues/128
It looks related, but I’m not sure how to change the code to make a patch to work with my project. If you could give me some pointers on how to do this (link to a resource/guide would be plenty) I’d love to test it.
@sklirg right, the issue is that
System.Net.HttpStatusCode
maps multiple enum values to the same underlyingint
value:https://github.com/dotnet/corefx/blob/master/src/System.Net.Primitives/src/System/Net/HttpStatusCode.cs
Utf8Json’s enum serialization does not currently handle this, but it’s a common enough case that it should be fixed in the client