question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't index json string into elastic search using Nest 7.13.0

See original GitHub issue

NEST/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:

  1. 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"
   }
}
  1. 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:

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:closed
  • Created 2 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
stevejgordoncommented, Jun 10, 2021

@LilanSilva If the request fails, you should see that on the response.

The following code works for me:

var client = new ElasticClient();

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 response = client.LowLevel.Index<StringResponse>("your-index-name", PostData.String(pp));

The response HttpStatusCode should be 201 and the AuditTrail on the response should include a HealthyResponse event. Because this is the low-level client and we specified StringResponse, the Body 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.

0reactions
LilanSilvacommented, Jun 16, 2021

Thanks for suggestions

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to index a json string (array of json objects) to ...
I want to be able to bulk index this json string directly to elastic search without having to deserialize it into a model...
Read more >
Elasticsearch Bulk Index JSON Data
What you need to do is to read that JSON file and then build a bulk request with the format expected by the...
Read more >
How to Index Json Data using NEST? · Issue #336
Lets say we have a class Test and it has 2 properties Name & Id. I want to store an object of this...
Read more >
Invalid NEST response built from a unsuccessful (200) low ...
I have a document already exists in an index in elastic below. r/elasticsearch - Elasticsearch .NET DocumentExists() returns error: Invalid ...
Read more >
Indexing and Searching Arbitrary JSON Data using ... - smnh
Indexing arbitrary JSON data, including nested arrays and objects, into Elasticsearch, without increasing type mapping.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found