Can't index json string into elastic search using Nest 7.13.0
See original GitHub issueNEST/Elasticsearch.Net version: 7.13.0
Elasticsearch version: v7.13.1
Description of the problem including expected versus actual behavior: I need to index dynamic json object into elastic search. I create the model with dynamic property
public class BookElasticSearch
{
public string Id { get; set; }
public string ApplicationId { get; set; }
public dynamic Metadata { get; set; }
}
Then deserialize json string and create BookElasticSearch object with it. Then Serialize that object and get string and index that json string
var basonDoc = JsonConvert.DeserializeObject(@"{
""emp-name"":""Kasun kalhara"",
""emp-age"":30,
""emp-position"":""Associate Developer""
}");
var tt = new BookElasticSearch
{
Id = Guid.NewGuid().ToString(),
Metadata = basonDoc
};
var pp = JsonConvert.SerializeObject(tt);
var indexResponse = await elasticClient.IndexAsync(pp, document => document.Index("book-index"));
Steps to reproduce:
- get Json string
{
"Id":"39f9af93-f315-40e7-bb42-8eebbd08bacb",
"ApplicationId": "application-34y7af93-f315-40e7-bb42-8eebbd08bvdr",
"Metadata":{
"emp-name":"Kasun kalhara",
"emp-age":30,
"emp-position":"Associate Developer"
}
}
- Index json string using “IndexAsync” method await elasticClient.IndexAsync(pp, document => document.Index(“book-index”));
Expected behavior Json string should index in elastic search
Provide ConnectionSettings
(if relevant):
Provide DebugInformation
(if relevant):
FailureReason: BadResponse while attempting POST on https://2c7809f98d7b4f78aca7ff6c819858dc.eastus.azure.elastic-cloud.com:9243/book-index/_doc
Audit trail of this API call:
- [1] BadResponse: Node: https://2c7809f98d7b4f78aca7ff6c819858dc.eastus.azure.elastic-cloud.com:9243/ Took: 00:00:01.7856567
OriginalException: Elasticsearch.Net.ElasticsearchClientException: Request failed to execute. Call: Status code 400 from: POST /book-index/_doc. ServerError: Type: mapper_parsing_exception Reason: “failed to parse” CausedBy: “Type: not_x_content_exception Reason: “not_x_content_exception: Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes””
Request:
<Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>
Response:
<Response stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>
Exception:
Elasticsearch.Net.ElasticsearchClientException: Request failed to execute. Call: Status code 400 from: POST /book-index/_doc. ServerError: Type: mapper_parsing_exception Reason: “failed to parse” CausedBy: “Type: not_x_content_exception Reason: “not_x_content_exception: Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes””
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (3 by maintainers)
Top GitHub Comments
@LilanSilva If the request fails, you should see that on the response.
The following code works for me:
The response
HttpStatusCode
should be 201 and theAuditTrail
on the response should include aHealthyResponse
event. Because this is the low-level client and we specifiedStringResponse
, theBody
of the response should be a string containing the JSON response from the server.If there are any failures, those locations should indicate what failed.
Thanks for suggestions