-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Indexing JObject documents does not work as expected #1609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm getting this when creating bulk descriptors of indexes using JObjects |
private async void blahblah(IEnumerable < JObject > jos)
{
var bdesc = new BulkDescriptor();
foreach (var jo in jos)
{
bdesc.Index(i => i
.Index(Index)
.Type("Trace")
.Document(jo));
}
//this yeilds the same as the above loop
//bdesc.IndexMany(jos, (f,g) => f.Index(Index).Type("Trace"));
var x = Client.Bulk(bdesc);
}
|
I've added some integration tests to NEST 2.x for This looks to be an issue only with NEST 1.x - @JulianRooze, @amccool, which version of NEST are you using? |
Using ElasticSearch.net 1.7.1 |
russcam
added a commit
that referenced
this issue
Feb 5, 2016
This is to handle serializing JObject using the Json.NET contract for it and not treating it as an IEnumerable<object> See #1609
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An issue occurs for us when you try to index a
JObject
as a document (using Nest) like this:The request fails with a 400 because of "malformed content". When you inspect the request being sent, the JSON at first appears to miss its opening bracket. It took me a while to figure it out but it's not a malformed object that's being sent, but rather a list of JSON properties concatenated by a newline. Properties don't start with a bracket which explains the missing bracket.
The reason that it's not serializing the JObject as an object is this code:
https://github.com/elastic/elasticsearch-net/blob/develop/src/Elasticsearch.Net/Connection/RequestHandlers/RequestHandlerBase.cs#L62
It checks if the data is an
IEnumerable<object>
, which is true because aJObject
is anIEnumerable<object>
and from then on it treats theJObject
as a list of items to serialize and not a singular object.Expected behavior for me would be that it just serialized the whole
JObject
at once and that it would be possible to index a document from aJObject
.The reason this behavior is unexpected to me is that using the search API to get back a JObject works perfectly. It also works for the update document API (we use the DocAsUpsert route as a workaround for this issue) but not with the index API. It also works as expected when you use the bulk API to index
JObject
documents.Suggested fix would be either a special-case check if
data is JObject
or perhaps fordata is IDictionary<string, object>
in which case it would just serialize the whole object as happens on line 66.The text was updated successfully, but these errors were encountered: