Code Monkey home page Code Monkey logo

Comments (7)

flobernd avatar flobernd commented on July 17, 2024 1

Hi @apr-un

I can't reproduce the main issue. The same code works perfectly fine on my side. Do you maybe have a network issue? Could you please run client.InfoAsync() to check if that's the case?

For the other problem, please try this:

var indexResponse = await _elasticClient.IndexAsync(document, index: indexName);

or

var indexResponse = await _elasticClient.IndexAsync(document, (IndexName)indexName);

from elasticsearch-net.

flobernd avatar flobernd commented on July 17, 2024 1

Could you please try this instead:

.DefaultMappingFor<DocumentDto>(x => x.IdProperty(p => p.Id))

As an alternative, try to remove the ToLowerInvariant as you are specifying the CLR type property and not the lower-case JSON representation.

In the NEST attribute you as well used nameof(Id) and not nameof(Id).ToLowerInvariant() 😅

from elasticsearch-net.

flobernd avatar flobernd commented on July 17, 2024 1

@apr-un Thanks for updating the post regarding the initial issue!

Happy to help! Don't hesitate to open a new issues if you have further questions.

from elasticsearch-net.

apr-un avatar apr-un commented on July 17, 2024

Thanks for fast reply :)
Methods You mentioned works - thanks 🥇

Code with IndexRequest started to work after I tested Your methods :o

client.InfoAsync() looks like doesn't await or like IndexAsync it just behaves weird during debug - I'm adding documents in loop, so it looks like it goes outside of my AddDocument function, then returns in random moments, but in console log it looks ok, so You're probably right about network issues...

I find that var indexResponse = await _elasticClient.IndexAsync(document) also works, but it is creating new document every time - it doesnt take Id from POCO model.

from elasticsearch-net.

flobernd avatar flobernd commented on July 17, 2024

I just tested IndexAsync and it seems to work as intended for me:

await client.IndexAsync(new Person { Id = 1290 });
Successful (201) low level call on PUT: /idx/_doc/1290?pretty=true&error_trace=true // <- inferred ID in the url

# Request:
{
  "id": 1290, // <- ID in the document
  "data": "NOTHING"
}

The second call successfully updates the document:

# Response:
{
  "_index" : "idx",
  "_id" : "1290",
  "_version" : 2,
  "result" : "updated",

Is your id property named correctly?

This is my test POCO type:

public class Person
{
	public int Id { get; set; }

from elasticsearch-net.

apr-un avatar apr-un commented on July 17, 2024

I think that everything is fine in my definition:

   public class DocumentDto
   {
       [JsonPropertyName("id")]
       public string Id { get; set; }

and in client settings:

var settings = new ElasticsearchClientSettings(_elasticSearchUri)
    .DefaultMappingFor<DocumentDto>(a => a.IdProperty(nameof(DocumentDto.Id).ToLowerInvariant()))

I used JsonPropertyName before and it works correctly (In 7.x client I marked my dto with [ElasticType(IdProperty = nameof(Id))] but I belive it's not supported anymore? )

from elasticsearch-net.

apr-un avatar apr-un commented on July 17, 2024

You're right, IdProperty shouldn't be lowercased :(
Your code works fine - I just need to change default index to be exactly named, not wildcard.

To be honest I'm"experimenting" with everything due to lack of complete more complex examples for .net client 8.x ;)
Thank You for support 👍

Edit:
I also figured out why my original function AddDocument seems to ignore await - it wasn't returning anything ( async void AddDocument ) so code just go right to adding next document... 🤦
It started to "behave correctly" after I changed it to return status of response 😄

from elasticsearch-net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.