Giter VIP home page Giter VIP logo

Comments (3)

flobernd avatar flobernd commented on July 19, 2024 1

The values that guided the choice make sense to me.

A default index is not a thing that we're interested in. We're looking for a more dynamic approach. But thanks anyway.

👍

By the way, once we have an implicit operator from IndexName and Id to string, we no longer need the overload with string; it's not gonna work anyway:

I would rather say it works too good 😄 Both IndexName and Id have implicit conversion operators from string. This unfortunately causes an ambiguity for which I have not yet decided how to solve it.

As a workaround you can either cast to e.g. IndexName like you did above, or specify the argument name explicitly:

=> client.IndexAsync(document, index: "index-name", token);

from elasticsearch-net.

flobernd avatar flobernd commented on July 19, 2024

Hi @AntonioFalcaoJr,

thanks for the feature request. What version of the Elasticsearch client are you currently using? I'm asking because there already is an IndexAsync overload in the ElasticsearchClient that supports index name inference:

public virtual Task<IndexResponse> IndexAsync<TDocument>(TDocument document, CancellationToken cancellationToken = default)

To use this method, you must specify the desired default index during initialization like this:

var settings = new ElasticsearchClientSettings(new Uri("https://..."))
	.Authentication(new BasicAuthentication("elastic", "..."))
	.DefaultMappingFor<Person>(x => x.IndexName("person")); // <- Set default index for 'Person'

var client = new ElasticsearchClient(settings);

await client.IndexAsync(new Person());

The implicit derivation of a lowercase index name from a specific type is problematic. We try to follow the principle of "explicit before implicit" to avoid as many surprises as possible. Not everyone uses an index name that is simply a lowercase representation of the entity name. Also, sometimes the same entity is stored in different indexes. For this reason, we want the user to explicitly configure the default index once during initialization.

Please let me know if that works for you 🙂

from elasticsearch-net.

AntonioFalcaoJr avatar AntonioFalcaoJr commented on July 19, 2024

I'm using version 8.13.12.

The values that guided the choice make sense to me.

A default index is not a thing that we're interested in. We're looking for a more dynamic approach. But thanks anyway.

By the way, once we have an implicit operator from IndexName and Id to string, we no longer need the overload with string; it's not gonna work anyway:

image

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.