Git Product home page Git Product logo

Comments (9)

sothawo avatar sothawo commented on July 21, 2024 2

I didn't want to rush you, it just might have been that some part of the autogeneration was not executed properly although it should. So there's no problem with that, there are still enough parts I can work on.
Btw, great work, I like that concept with the Transport and the Endpoint that helps a lot in building a reactive Elasticsearch Client that can reuse the code to build requests and parse responses.

When this will be released we can have a great cleanup of code in Spring Data Elasticsearch, looking forward to it.

I'll close this issue and patiently wait for the next releases.

from elasticsearch-java.

sothawo avatar sothawo commented on July 21, 2024 2

Having some reactive client would be nice; currently I have an implementation where I add reactive versions of the imperative part (if you have spare time you can look at what I did here: https://github.com/sothawo/spring-data-elasticsearch/tree/new-Elasticsearch-client/src/main/java/org/springframework/data/elasticsearch/clients/reactive/elasticsearch - still work in progress as well).

The problem is that I have to make sure that all the methods that exist in the imperative part are adapted to the reactive part. Having some base class or interface would help.

But I think that is not necessarily needed for the first version, it's more important to have all the requests and responses available.

btw, the RestClient implements Closeable and should be closed when not used anymore. Would it make sense to make ElasticsearchClient implement AutoCloseable and pass a call to close() down to the RestClient?

from elasticsearch-java.

vijaykriishna avatar vijaykriishna commented on July 21, 2024 1

Going on with my tests I wanted to create a simple match query for a call like this:

GET /test-index/_search
{
  "query": {
    "match": {
      "message": {
        "query": "this is a test"
      }
    }
  }
}

I try to use this code:

		SearchRequest searchRequest = new SearchRequest.Builder()
				.index("test-index")
				.query(b -> b
						.match(
								// what to use here????
						))
				.build();

The QueryContainer.Builder has these 2 match methods:

        public ObjectBuilder<QueryContainer> match(NamedQuery<JsonValue> v) {
            this.$variant = v;
            this.$tag = QueryContainer.Tag.match;
            return new Constant(this.build());
        }

        public ObjectBuilder<QueryContainer> match(Function<co.elastic.clients.elasticsearch._types.query_dsl.NamedQuery.Builder<JsonValue>, ObjectBuilder<NamedQuery<JsonValue>>> f) {
            return this.match((NamedQuery)((ObjectBuilder)f.apply(new co.elastic.clients.elasticsearch._types.query_dsl.NamedQuery.Builder())).build());
        }

what would I need to put there? I am missing a MatchQuery class here. Or something like

.match(m -> m.field("message").query("this is a test").build()

The same problem comes up when trying to build a simple terms query.

Hi @sothawo
Based on my understanding of your requirement, Match Query would be as follows.

SearchSourceBuilder builder = new SearchSourceBuilder().query(QueryBuilders.matchQuery("Dest", "Zurich Airport"));
SearchResponse response = client.search(new SearchRequest().source(builder).indices("kibana_sample_data_flights"), RequestOptions.DEFAULT);

Field Name: Dest
Value: Zurich Airport

Generated Query:

GET /kibana_sample_data_flights/_search
{
  "query": {
    "match": {
      "Dest": {
        "query": "Zurich Airport",
        "operator": "OR",
        "prefix_length": 0,
        "max_expansions": 50,
        "fuzzy_transpositions": true,
        "lenient": false,
        "zero_terms_query": "NONE",
        "auto_generate_synonyms_phrase_query": true,
        "boost": 1
      }
    }
  }
}

As you see, there are few customisable properties in the generated query. They can be changed in Java based implementation of the query shared above, based on the requirement.

I've used sample dataset that comes with default ES (7.9.1) / Kibana(7.9.1) installation.
Pls do share the requirement for Terms Query incase you need help.

BR
-Vijay-

from elasticsearch-java.

sothawo avatar sothawo commented on July 21, 2024 1

@vijaykriishna SearchSourceBuilderis a class from the core Elasticsearch libraries and is used in the RestHighlevelClient.

The code in this repository is for the new Elasticsearch Client which does not depend on these core libraries and has it's own classes and builders (but alas there are some missing).

from elasticsearch-java.

swallez avatar swallez commented on July 21, 2024 1

@sothawo that part of the code generator is still in flux, and support for these polymorphic types is not yet fully implemented. Gaps in the code generator are visible every time you see a property of type JsonValue. I've been busy on the main ES code base in the past week, but reaching feature completion of the code generator is my next priority.

I understand you're very interested in this new client, and this is awesome, but please be patient: as stated it's still a work in progress!

from elasticsearch-java.

swallez avatar swallez commented on July 21, 2024 1

Thanks the the feeback @sothawo! I feel your excitement, and it motivates us to do some good work even if it adds pressure 😉

BTW, would it help it we also generated a 3rd version of the API client classes based on reactive streams, e.g. ElasticsearchStreamClient alongside ElasticsearchClient and ElasticsearchAsyncClient? That one would be based on a reactive transport interface that could then be implemented with Spring's WebClient.

Or is the current strong separation between json handling, endpoints and data structures enough for your needs?

from elasticsearch-java.

daroay avatar daroay commented on July 21, 2024 1

How do you see the generated json query, before sending it to the client?

from elasticsearch-java.

swallez avatar swallez commented on July 21, 2024

Ok, thanks for the feedback. Indeed correct data structures is the top priority now, and we can consider a reactive version later.

Regarding AutoCloseable this is a good point and it indeed makes total sense!

from elasticsearch-java.

aliakseiGit avatar aliakseiGit commented on July 21, 2024

what would I need to put there? I am missing a MatchQuery class here. Or something like

.match(m -> m.field("message").query("this is a test").build()

Sorry for interfere. I have been looking for a long time for a solution to the same problem of searching by fields and terms of a document. So maybe it may help.

.match(m -> m.field("message").query(v -> v.stringValue("this is a test")).build()

And when you have to search by term you may do this:

        final SearchRequest searchRequest = new SearchRequest.Builder()
                .index("test-index")
                .query(q -> q.
                        term(t -> t
                            .field("nameOfTheField")
                            .value(v -> v.stringValue("value"))))
                .build();

from elasticsearch-java.

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.