Comments (7)
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.
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.
@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.
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.
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.
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.
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)
- Fluent API for composite aggregation sources
- IndexSettingsConverter tries to deserialize routing_path as collection of string even if there is a string in raw JSON response HOT 1
- ESQL Arrow support
- Implement Connectors API
- Add back TermsRangeQuery in the Elasticsearch .Net Client HOT 1
- error in elastic client when trying to get the mappings HOT 5
- Cannot run knn query using elasticClient.RequestResponseSerializer HOT 4
- Improve usability of `FiltersAggregation` HOT 1
- ElasticsearchClient.Indicies.GetAsync throws UnexpectedTransportException
- IndexSettings NumberOfShards and NumberOfReplicas are objects, not int/long as expected HOT 4
- Being more careful with releases HOT 1
- upsert operation and refresh set to 3s HOT 1
- Removing an single alias for indices throws 404 index not found HOT 4
- Using Must overload that accepts collection of Query objects doesn't work HOT 3
- KNNQuery Inner Hits HOT 3
- Allow use of Elasticsearch icon in .NET Aspire components? HOT 1
- Support OpentTelemetry Metrics HOT 2
- GetRepositoryResponse is unusable as it does not expose the actual response data
- MultiGetRequest does not serialize request parameters for SourceConfigParam properly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elasticsearch-net.