Official Elasticsearch Java Client

Overview

Elastic logo

Elasticsearch Java Client

The official Java client for Elasticsearch.


Note: this project is still a work in progress. This client is meant to replace the existing Java High Level Client and remove all dependencies to the Elasticsearch server code base.


The Java client for Elasticsearch provides strongly typed requests and responses for all Elasticsearch APIs. It delegates protocol handling to an http client such as the Elasticsearch Low Level REST client that takes care of all transport-level concerns (http connection establishment and pooling, retries, etc).

The docs/design folder contains records of the major decisions in the design of the API. Most notably:

  • Object construction is based on the fluent builder pattern.
  • Nested objects can be constructed with builder lambdas, allowing for clean and expressive DSL-like code.
  • Optional values are represented as null with @Nullable annotations instead of the newer Optional, the Java ecosystem being still very null-based.

Getting started

Installing the library

While it's a work in progress, snapshots of this library are published to a Maven repository hosted on GitHub Packages. To access it you need a personal access token on your GitHub account that has the read:packages permission. This token should then be added to ~/.gradle/gradle.properties:

ESJavaGithubPackagesUsername=YOUR_GITHUB_USERNAME
ESJavaGithubPackagesPassword=YOUR_GITHUB_TOKEN

Along with this library, you also need a JSON/object mapping library. elasticsearch-java has built-in support for Jackson and JSON-B implementations such as Eclipse Yasson.

This library requires at least Java 8.

Gradle project (Groovy flavor) setup using Jackson:

repositories {
    mavenCentral()
    maven {
        name = "ESJavaGithubPackages"
        url = uri("https://maven.pkg.github.com/elastic/elasticsearch-java")
        credentials(PasswordCredentials)
    }
}

dependencies {
    implementation 'co.elastic.clients:elasticsearch-java:8.0.0-SNAPSHOT'
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3'
}

If you are using Maven, you need to add the credentials in your ~/.m2/settings.xml:

<settings>
  <servers>
    <server>
      <id>ESJavaGithubPackages</id>
      <username>YOUR_GITHUB_USERNAME</username>
      <password>YOUR_GITHUB_TOKEN</password>
    </server>
  </servers>
</settings>

In the pom.xml for your project add the following repository definition and dependencies:

<project>
    
  <repositories>
    <repository>
      <id>ESJavaGithubPackages</id>
      <url>https://maven.pkg.github.com/elastic/elasticsearch-java</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      </repository>
  </repositories>
    
  <dependencies>
    <dependency>
      <groupId>co.elastic.clients</groupId>
      <artifactId>elasticsearch-java</artifactId>
      <version>8.0.0-SNAPSHOT</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.12.3</version>
    </dependency>
  </dependencies>
    
</project>

Your first request

// Create the low-level client
RestClient restClient = RestClient.builder(new HttpHost("localhost", 9200)).build();

// Create the transport that provides JSON and http services to API clients
Transport transport = new RestClientTransport(restClient, new JacksonJsonpMapper());

// And create our API client
ElasticsearchClient client = new ElasticsearchClient(transport);

// Search all items in an index that contains documents of type AppData
SearchResponse search = client.search(s -> s
    .index("test-index"),
    AppData.class
);

if (search.hits().hits().isEmpty()) {
    System.out.println("No match");
} else {
    for (Hit<AppData> hit : search.hits().hits()) {
        processAppData(hit._source());
    }
}

Compatibility

The main branch targets the upcoming Elasticsearch 8.0. Support is still incomplete as the API code is generated from the Elasticsearch Specification that is also still a work in progress.

As the work on the specification comes to completion, an additional 7.x branch will provide support for the corresponding versions of Elasticsearch.

Current status

While not complete, this library is already fairly usable. What's missing falls in two main categories, related to the Elasticsearch specification:

  • incomplete support for some data types used in specification (e.g. unions). Until they have been implemented in the code generator, they are represented as raw JsonValue objects.
  • incomplete APIs: as the API specification is still incomplete, so are their implementations in this library since their code is entirely generated from the spec.

Contributing

See CONTRIBUTING.md

Licence

This software is licensed under the Apache License 2.0.

Comments
  • [es/snapshot.create] Missing [X-Elastic-Product] header

    [es/snapshot.create] Missing [X-Elastic-Product] header

    Elasticsearch version (bin/elasticsearch --version): 7.16.2

    Plugins installed: []

    JVM version (java -version):

    openjdk version "11.0.13" 2021-10-19
    OpenJDK Runtime Environment (build 11.0.13+8-Ubuntu-0ubuntu1.21.10)
    OpenJDK 64-Bit Server VM (build 11.0.13+8-Ubuntu-0ubuntu1.21.10, mixed mode, sharing)
    

    OS version (uname -a if on a Unix-like system):

    Linux pop-os 5.15.8-76051508-generic #202112141040~1639505278~21.10~0ede46a SMP Tue Dec 14 22:38:29 U x86_64 x86_64 x86_64 GNU/Linux

    Description of the problem including expected versus actual behavior:

    When performing a snapshot using the new Java client, it fails due to missing X-Elastic-Product header sent by Elasticsearch.

    Steps to reproduce:

    Please include a minimal but complete recreation of the problem, including (e.g.) index creation, mappings, settings, query etc. The easier you make for us to reproduce it, the more likely that somebody will take the time to look at it.

    1. Create an FS repository,
    2. Create a snapshot using the new java client:
    final CreateSnapshotRequest request = new CreateSnapshotRequest
      .Builder()
      .repository(repository)
      .snapshot(name)
      .waitForCompletion(waitForCompletion)
      .build();
    client.create(request);
    

    Client being used (maven dep):

    <elasticsearch.version>7.16.2</elasticsearch.version>
    
    ...
    
          <dependency>
            <groupId>co.elastic.clients</groupId>
            <artifactId>elasticsearch-java</artifactId>
            <version>${elasticsearch.version}</version>
          </dependency>
    
    1. The code throws an exception.

    Provide logs (if relevant):

    co.elastic.clients.transport.TransportException: [es/snapshot.create] Missing [X-Elastic-Product] header. Please check that you are connecting to an Elasticsearch instance, and that any networking filters are preserving that header.
    
    	at co.elastic.clients.transport.rest_client.RestClientTransport.checkProductHeader(RestClientTransport.java:340)
    	at co.elastic.clients.transport.rest_client.RestClientTransport.getHighLevelResponse(RestClientTransport.java:250)
    	at co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:144)
    	at co.elastic.clients.elasticsearch.snapshot.ElasticsearchSnapshotClient.create(ElasticsearchSnapshotClient.java:142)
    
    v8.0.0 v7.17.0 
    opened by jloisel 21
  • Is there a replacement for the BulkProcessor?

    Is there a replacement for the BulkProcessor?

    With RHLC, one could use the BulkProcessor API to batch IndexRequests and DeleteRequests. Is there a recommended replacement for BulkProcessor when migrating to elasticsearch-java?

    https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-docs-bulk-processor.html

    >enhancement v7.16.2 
    opened by tony-hizzle 19
  • Raw json support

    Raw json support

    Fixes #143

    Adds withJson methods to object builders. These methods populate an object builder from arbitrary JSON by using its deserializer. This allows creating API objects with a combination of programmatic call to property setters and arbitrary JSON data.

    The main use cases are loading search requests, index mappings or documents from arbitrary JSON sources.

    >enhancement backport 7.17 backport 8.1 
    opened by swallez 13
  • indices client and xcontent/json support

    indices client and xcontent/json support

    Hello and I have a question: I am trying out this new fluent client and have a bunch of projects that I wanted to migrate from the RHLC to the new API client. Now I am kinda stuck on an inconvenient spot, creating an index with settings and mapping. the builder and functional pattern are nice, though in our projects we put json-files for mappings and settings which are read and converted into an object/xContentBuilder so we do not have to implement complex settings/mappings into java code (and reuse without copy paste).

    kinda like that

    CreateIndexRequest createIndexRequest = new CreateIndexRequest(indexName)
    				.settings(this.elasticsearchIndexService.createSettings(ELASTICSEARCH_INDEX_SETTINGS_FILE))
    				.mapping(this.elasticsearchIndexService.createMapping(ELASTICSEARCH_INDEX_MAPPING_FILE,
    					ELASTICSEARCH_INDEX_MAPPING_FOLDER, shop));
    AcknowledgedResponse indexCreateResponse = this.restHighLevelClient.indices().create(createIndexRequest, RequestOptions.DEFAULT);
    

    depending on the shop parameter different mappings are loaded.

    Is there a similar and fluent way doing that in the new client or are there any plans supporting json/xcontent?

    >documentation >enhancement question 
    opened by UglyBarnacle 13
  • ElasticsearchIndicesClient#getMapping(GetMappingRequest) throws on reading response when mapping contains an object property

    ElasticsearchIndicesClient#getMapping(GetMappingRequest) throws on reading response when mapping contains an object property

    Using version 7.15.2.

    When an index mapping contains a property that is an object, co.elastic.clients.elasticsearch.indices.ElasticsearchIndicesClient#getMapping(co.elastic.clients.elasticsearch.indices.GetMappingRequest) crashes on parsing the result.

    This can be tested with the following code:

    class Name {
    	String first;
    	String last;
    
    	public Name(String first, String last) {
    		this.first = first;
    		this.last = last;
    	}
           // getter+setter
    }
    
    class Person {
    	String id;
    	Name name;
    
    	public Person(String id, Name name) {
    		this.id = id;
    		this.name = name;
    	}
           // getter+setter
    }
    
    ElasticsearchClient client = ... // setup the ElasticsearchClient
    String index = "testindex";
    Person person = new Person("42", new Name("Ford", "Prefect"));
    client.index(b -> b.index(index).id(person.id).document(person));
    GetMappingResponse getMappingResponse = client.indices().getMapping(mrb -> mrb.index(index));
    
    

    This will produce the following error:

    jakarta.json.stream.JsonParsingException: Property 'type' not found
    
    	at co.elastic.clients.json.JsonpUtils.lookAheadFieldValue(JsonpUtils.java:139)
    	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:128)
    	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:95)
    	at co.elastic.clients.json.BuildFunctionDeserializer.deserialize(BuildFunctionDeserializer.java:42)
    	at co.elastic.clients.json.JsonpDeserializer$LazyDeserializer.deserialize(JsonpDeserializer.java:205)
    	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:102)
    	at co.elastic.clients.json.JsonpDeserializer$StringMapDeserializer.deserialize(JsonpDeserializer.java:461)
    	at co.elastic.clients.json.JsonpDeserializer$StringMapDeserializer.deserialize(JsonpDeserializer.java:447)
    	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:102)
    	at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:68)
    	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:122)
    	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:95)
    	at co.elastic.clients.json.BuildFunctionDeserializer.deserialize(BuildFunctionDeserializer.java:42)
    	at co.elastic.clients.json.JsonpDeserializer$LazyDeserializer.deserialize(JsonpDeserializer.java:205)
    	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:102)
    	at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:68)
    	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:122)
    	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:95)
    	at co.elastic.clients.json.BuildFunctionDeserializer.deserialize(BuildFunctionDeserializer.java:42)
    	at co.elastic.clients.json.JsonpDeserializer$LazyDeserializer.deserialize(JsonpDeserializer.java:205)
    	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:102)
    	at co.elastic.clients.base.DictionaryResponse.lambda$setupDictionaryResponseDeserializer$0(DictionaryResponse.java:148)
    	at co.elastic.clients.json.ObjectDeserializer.parseUnknownField(ObjectDeserializer.java:150)
    	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:120)
    	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:95)
    	at co.elastic.clients.json.BuildFunctionDeserializer.deserialize(BuildFunctionDeserializer.java:42)
    	at co.elastic.clients.json.JsonpDeserializer$LazyDeserializer.deserialize(JsonpDeserializer.java:205)
    	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:102)
    	at co.elastic.clients.base.rest_client.RestClientTransport.getHighLevelResponse(RestClientTransport.java:242)
    	at co.elastic.clients.base.rest_client.RestClientTransport.performRequest(RestClientTransport.java:104)
    	at co.elastic.clients.elasticsearch.indices.ElasticsearchIndicesClient.getMapping(ElasticsearchIndicesClient.java:1044)
    	at co.elastic.clients.elasticsearch.indices.ElasticsearchIndicesClient.getMapping(ElasticsearchIndicesClient.java:1061)
    

    The mapping returned from the server:

    {
      "testindex" : {
        "mappings" : {
          "properties" : {
            "id" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "name" : {
              "properties" : {
                "first" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                },
                "last" : {
                  "type" : "text",
                  "fields" : {
                    "keyword" : {
                      "type" : "keyword",
                      "ignore_above" : 256
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    

    I debugged through the code; when reading the properties, the parser comes to the name entry and then on finding a START_OBJECT tries to get the type property of the object, basically expecting something like

    {
        "type": "object",   <===  Elasticsearch does not send a type entry here
        "properties": {
          "first": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "last": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
    

    Even when the mapping is stored explicitly in Elasticsearch with the type object, it is not returned on getting the mapping.

    >bug v7.16.0 
    opened by sothawo 12
  • Wrapper query implementation missing

    Wrapper query implementation missing

    Client version 7.16.1:

    It seems that the co.elastic.clients.elasticsearch._types.query_dsl.Query is missing the wrapper query type (https://www.elastic.co/guide/en/elasticsearch/reference/7.16/query-dsl-wrapper-query.html).

    v7.16.0 >api-spec:fixed 
    opened by sothawo 11
  • Put Lifecycle method in ILM Client causes 400 Bad Request

    Put Lifecycle method in ILM Client causes 400 Bad Request

    The PUT Lifecycle Endpoint send the name as a property in the body, which is not accepted by Elasticsearch. This causes a 400 Bad Request Response. Therefore this method is not usable.

    Code

    Application

    client.ilm().putLifecycle(it -> {
        it.name(policy.name())
        it.policy(policy)
    });
    

    Request

    Endpoint: PUT /_ilm/policy/{id}

    {
      "policy": {
        "phases": {...},
        "name": "{id}"
      }
    }
    

    Response

    Status: 400 Bad Request

    {
      "error": {
        "root_cause": [
          {
            "type": "x_content_parse_exception",
            "reason": "[1:94] [lifecycle_policy] unknown field [name]"
          }
        ],
        "type": "x_content_parse_exception",
        "reason": "[1:101] [put_lifecycle_request] failed to parse field [policy]",
        "caused_by": {
          "type": "x_content_parse_exception",
          "reason": "[1:94] [lifecycle_policy] unknown field [name]"
        }
      },
      "status": 400
    }
    
    >api-spec 
    opened by raynigon 10
  • Map Builders should preserve order

    Map Builders should preserve order

    Object Builders for maps use an InternalMap which is a sub-class of a hash map:

    https://github.com/elastic/elasticsearch-java/blob/75feae536d2c9bce755236c979416fd9d0652803/java-client/src/main/java/co/elastic/clients/util/ObjectBuilderBase.java#L91

    Hash maps are unordered, the order is defined by the internal hashing function and can be different for different runtime environments. Although the JSON standard does not define dictionaries to be ordered, it would be good to switch to a linked hash map with insertion order:

    • for a user the order might have a meaning and it is easier for them if the order is preserved the way the user specified it, e.g. the output might be a ML job or transform configuration
    • in some cases order can be important at runtime: https://github.com/elastic/elasticsearch/issues/82350

    Because this does not seems performance-critical, I suggest to switch to a linked hash map with insertion order

    >enhancement v7.16.2 
    opened by hendrikmuhs 9
  • How can I create a simple match query?

    How can I create a simple match query?

    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.

    opened by sothawo 9
  • Complete refernce document not available for Elasticsearch new Java Client

    Complete refernce document not available for Elasticsearch new Java Client

    Description

    There is no complete reference document available for the new Java client. We have good documentation for Java High Level client, which is deprecated now. I have check this documentation but it is not much useful.

    • UpdateRquest example
    • DeleteRequest example
    • Various Index API
    • Multi Search API
    • Search teamplate API
    • Update By Query API
    • Delete By Query API

    It will be gerat if we have Java client document same as Java High Level client.

    >documentation 
    opened by sagarpatel07 8
  • TermSuggest options should be an array

    TermSuggest options should be an array

    Java API client version

    8.1.1

    Java version

    11

    Elasticsearch Version

    8.1.0

    Problem description

    I try to execute a search requesting a term-suggester:

    {
      "query": {
        "bool": {
          "must": [
            {
              "multi_match": {
                "analyzer": "full_analyzer",
                "fields": [
                  "searchText^1",
                  "searchTextBoosted^4.0",
                ],
                "operator": "and",
                "query": "Stabi",
                "type": "cross_fields"
              }
            }
          ]
        }
      },
      "from": 0,
      "size": 20,
      "sort": [
        {
          "_score": {
            "order": "desc"
          }
        }
      ],
      "suggest": {
        "name.suggest": {
          "term": {
            "field": "searchTextBoosted",
            "suggest_mode": "missing"
          }
        },
        "text": "Stabi"
      }
    }
    

    The result looks good:

    {
      "took": 10,
      "timed_out": false,
      "_shards": {
        "total": 3,
        "successful": 3,
        "skipped": 0,
        "failed": 0
      },
      "hits": {
        "total": {
          "value": 2,
          "relation": "eq"
        },
        "max_score": 3.4410129,
        "hits": [
          {
            "_index": "my-index",
            "_id": "BP-xtn8BLc_6fF5-zBDh",
            "_score": 3.4410129,
            "_source": {
              // stuff ...
            }
          }
        ]
      },
      "suggest": {
        "term#name.suggest": [
          {
            "text": "stabi",
            "offset": 0,
            "length": 5,
            "options": [
              {
                "text": "stab",
                "score": 0.75,
                "freq": 2
              },
              {
                "text": "stand",
                "score": 0.6,
                "freq": 2
              }
            ]
          },
          {
            "text": "stab",
            "offset": 0,
            "length": 5,
            "options": []
          }
        ]
      }
    }
    

    But the Java Client is not happy, because it thinks that the "options"-field in the term-suggester's result should be an object rather than an array. This causes the following error: co.elastic.clients.json.UnexpectedJsonEventException: Unexpected JSON event 'START_ARRAY' instead of '[START_OBJECT, KEY_NAME]' at co.elastic.clients.json.JsonpUtils.ensureAccepts(JsonpUtils.java:103) ~[elasticsearch-java-8.1.1.jar:?]

    This is probably due to the code-generation that this library uses. I think that the specification is incorrect. Looking at the options of a completion-suggester (https://github.com/elastic/elasticsearch-specification/blob/7b8304b279b50f87239c0d83262a1f0fd2963a2a/specification/_global/search/_types/suggester.ts#L51):

    export class CompletionSuggest<TDocument> extends SuggestBase {
      options: CompletionSuggestOption<TDocument>[]
    }
    

    And looking at the options of a term-suggester (https://github.com/elastic/elasticsearch-specification/blob/7b8304b279b50f87239c0d83262a1f0fd2963a2a/specification/_global/search/_types/suggester.ts#L65):

    export class TermSuggest extends SuggestBase {
      options: TermSuggestOption
    }
    

    This looks wrong, the result that elasticsearch returns is clearly an Array of options.

    PS: PhraseSuggest looks wrong too (https://github.com/elastic/elasticsearch-specification/blob/7b8304b279b50f87239c0d83262a1f0fd2963a2a/specification/_global/search/_types/suggester.ts#L58):

    export class PhraseSuggest extends SuggestBase {
      options: PhraseSuggestOption
    }
    

    Cheers Lukas

    >api-spec 
    opened by LukasSeglias 8
  • java.lang.IllegalArgumentException: Class class co.elastic.clients.elasticsearch.core.bulk.UpdateOperation cannot be read from JSON

    java.lang.IllegalArgumentException: Class class co.elastic.clients.elasticsearch.core.bulk.UpdateOperation cannot be read from JSON

    Java API client version

    8.5.3 and 8.4.1

    Java version

    jdk11

    Elasticsearch Version

    8.4.1

    Problem description

    java.lang.IllegalArgumentException: Class class co.elastic.clients.elasticsearch.core.bulk.UpdateOperation cannot be read from JSON

    StringReader reader = new StringReader(json);
                BulkOperation updateOp = new BulkOperation.Builder()
                                .update(new UpdateOperation.Builder<>()
                                .index(topic)
                                .id("1")
                                .withJson(reader)
                                .retryOnConflict(Math.min(1, 5))
                                .build())
                        .build();
    

    image image

    opened by lucky-xin 0
  • Retrieving ids: REST request succeeds but not using Java Client

    Retrieving ids: REST request succeeds but not using Java Client

    Java API client version

    8.5

    Java version

    8

    Elasticsearch Version

    8.5.3

    Problem description

    I am trying to retrieve all (elasticsearch) Ids of an index using the following code.

        SearchRequest sr = SearchRequest.of(r -> r
            .index("my_index")
            .source(s -> s.fetch(false))
            .size(10000));
    
        System.out.println("Request: " + sr);
    
        final SearchResponse<MyDoc> response;
        try {
            response = this.esClient.search(sr, MyDoc.class);
        } catch (ElasticsearchException | IOException e) {
            throw new MyException("fetch all ids: request failed: " + e.getMessage(), e);
        }
    
        System.out.println("Response: " + response);
    

    There are no results in the response. However, the printed request is

    POST /my_index/_search?typed_keys=true {"_source":false,"size":10000}
    

    which works perfectly fine when run directly as a REST request.

    Any idea how to do it using the Java client?

    The REST response is

    {
      "took": 1,
      "timed_out": false,
      "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
      },
      "hits": {
        "total": {
          "value": 999,
          "relation": "eq"
        },
        "max_score": 1,
        "hits": [
          {
            "_index": "my_index",
            "_id": "2LHJSP6dTjXuEM2vsEDyxdG4Y7HPzXL15tFvrkyZm8xn",
            "_score": 1
          },
          {
            "_index": "my_index",
            "_id": "A8RCf2mV4qeWvLxSfzKNX418E734uEifCenoCAiM3syB",
            "_score": 1
          },
          ...
        ]
      }
    }
    
    opened by bgrieder 0
  • Missing required property 'IndexResponse.primaryTerm'

    Missing required property 'IndexResponse.primaryTerm'

    Java API client version

    8.5.1

    Java version

    17

    Elasticsearch Version

    8.5.3

    Problem description

    When using the index api with a pipeline that returns noop, the _primary_term property is not present in the response, which leads to this exception:

    Missing required property 'IndexResponse.primaryTerm'
    co.elastic.clients.util.MissingRequiredPropertyException: Missing required property 'IndexResponse.primaryTerm'
    

    The workaround provided at MissingRequiredPropertyException does not work as it throws another exception:

    Cannot invoke "java.lang.Long.longValue()" because the return value of "co.elastic.clients.util.ApiTypeHelper.requireNonNull(Object, Object, String)" is null
    java.lang.NullPointerException: Cannot invoke "java.lang.Long.longValue()" because the return value of "co.elastic.clients.util.ApiTypeHelper.requireNonNull(Object, Object, String)" is null
    

    Using dev tools to test the pipeline, we can see that the _primary_term property is not present in the response

    // PIPELINE RETURNING NOOP
    PUT _ingest/pipeline/noop-pipeline
    {
      "processors": [
        {
          "drop": {
            "if": "true"
          }
        }
      ]
    }
    
    PUT test-index/_doc/test?pipeline=noop-pipeline
    {
      "test": "test"
    }
    
    // PIPELINE RETURNING CREATED
    PUT _ingest/pipeline/created-pipeline
    {
      "processors": [
        {
          "drop": {
            "if": "false"
          }
        }
      ]
    }
    
    PUT test-index/_doc/test?pipeline=created-pipeline
    {
      "test": "test"
    }
    
    

    Responses:

    # PUT _ingest/pipeline/noop-pipeline 200 OK
    {
      "acknowledged": true
    }
    # PUT test-index/_doc/test?pipeline=noop-pipeline 200 OK
    {
      "_index": "test-index",
      "_id": "test",
      "_version": -3,
      "result": "noop",
      "_shards": {
        "total": 0,
        "successful": 0,
        "failed": 0
      }
    }
    # PUT _ingest/pipeline/created-pipeline 200 OK
    {
      "acknowledged": true
    }
    # PUT test-index/_doc/test?pipeline=created-pipeline 201 Created
    {
      "_index": "test-index",
      "_id": "test",
      "_version": 1,
      "result": "created",
      "_shards": {
        "total": 2,
        "successful": 1,
        "failed": 0
      },
      "_seq_no": 0,
      "_primary_term": 1
    }
    
    opened by Joaonic 0
  • JsonpUtils#objectParser toString roundtrip to deserialise object uses ~30%more CPU

    JsonpUtils#objectParser toString roundtrip to deserialise object uses ~30%more CPU

    Java API client version

    <= 7.17

    Java version

    17

    Elasticsearch Version

    7.17 and 8.5

    Problem description

    Hey

    I'm in the process of migrating from the old elastic search client that has been deprecated.

    While testing we've noticed higher CPU load when running servers.

    From observations I'd say ~30% higher cpu load to what we have with deprecated client. If we decide to pull the trigger on migration it'll mean we'll have to run more replicas of the service which is talking to elastic and it means more $$$ we'll have to spend on infrastructure.

    We use multi search requests which I think is important at this point as running regular search requests has no performance penalty.

    Looking at profiler cpu sampling I've noticed that around 30% of deserialising multi search response is spend in co.elastic.clients.json.JsonpUtils#objectParser and current implementation of this method is some kind of a workaround put in there around one year ago:

    String strObject = object.toString();
    return mapper.jsonProvider().createParser(new StringReader(strObject));
    

    This is not very CPU friendly (and as a result cost effective implementation).

    I'm wondering if this workaround is still necessary or if there is any better way of doing this now.

    I'll be happy to do some testing but at this point I think I know too little about json providers, factories, parsers, mappers and other things that are going on with json serialisation and deserialisation to be of any real help.

    opened by pchudzik 0
  • Percentiles(Kind=Keyed) order is not right

    Percentiles(Kind=Keyed) order is not right

    Java API client version

    8.5.3

    Java version

    17

    Elasticsearch Version

    8.5.3

    Problem description

    ElasticsearchClient elasticsearchClient = new ElasticsearchClient(getElasticsearchTransport(getRestClient()));
    SearchRequest.Builder builder = new SearchRequest.Builder();
    builder.index("elasticsearch-sql_test_index_account");
    builder.query(Query.of(q -> q.matchAll(MatchAllQuery.of(e -> e))));
    builder.aggregations("percentiles(age)", Aggregation.of(a -> a.percentiles(PercentilesAggregation.of(
            e -> e.percents(1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0).field("age")
    ))));
    builder.size(0);
    SearchRequest searchRequest = builder.build();
    SearchResponse<Object> searchResponse = elasticsearchClient.search(searchRequest, Object.class);
    System.out.println(searchResponse);
    

    output:

    SearchResponse: {
      "took": 4,
      "timed_out": false,
      "_shards": {
        "failed": 0,
        "successful": 1,
        "total": 1,
        "skipped": 0
      },
      "hits": {
        "total": {
          "relation": "eq",
          "value": 1000
        },
        "hits": [],
        "max_score": null
      },
      "aggregations": {
        "tdigest_percentiles#percentiles(age)": {
          "values": {
            "25.0": "25.0",
            "1.0": "20.0",
            "95.0": "39.0",
            "50.0": "31.0",
            "5.0": "21.0",
            "99.0": "40.0",
            "75.0": "35.0"
          }
        }
      }
    }
    

    but expected:

    ...
      "aggregations": {
        "tdigest_percentiles#percentiles(age)": {
          "values": {
            "1.0": "20.0",
            "5.0": "21.0",
            "25.0": "25.0",
            "50.0": "31.0",
            "75.0": "35.0",
            "95.0": "39.0",
            "99.0": "40.0"
          }
    ...
    

    co.elastic.clients.elasticsearch._types.aggregations.Percentiles#buildPercentilesDeserializer use co.elastic.clients.json.JsonpDeserializerBase.StringMapDeserializer, but it's co.elastic.clients.json.JsonpDeserializerBase.StringMapDeserializer#deserialize method use HashMap,

    I think, it should use LinkedHashMap to keep the order: image

    opened by shi-yuan 0
  • get task status of forcemerge(wait_for_completion=false) results in error when task completed

    get task status of forcemerge(wait_for_completion=false) results in error when task completed

    Java API client version

    8.5.2

    Java version

    1.8

    Elasticsearch Version

    8.5.0

    Problem description

    when submit a force merge request with wait_for_completion=false, i got a taskid. and I use task id to query task status

     logger.info("force merge taskId: {}", taskId);
    boolean completed = false;
    GetTasksResponse tasksResponse = null;
    while (!completed) {
        tasksResponse = client.tasks().get(t -> t.taskId(taskId));
        completed = tasksResponse.completed();
        logger.info("force merge task not completed yet");
        try {
            Thread.sleep(2 * 60_000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
    

    all seems good when task is still running. but when task finally completes, get task response throws exception

    Error deserializing co.elastic.clients.elasticsearch.tasks.GetTasksResponse: co.elastic.clients.util.MissingRequiredPropertyException: Missing required property 'TaskStatus.batches' (JSON path: response) (line no=1, column no=449, offset=-1)
    	at co.elastic.clients.json.JsonpMappingException.from0(JsonpMappingException.java:134)
    	at co.elastic.clients.json.JsonpMappingException.from(JsonpMappingException.java:121)
    	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:218)
    	at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:148)
    	at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:76)
    	at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:79)
    	at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43)
    	at co.elastic.clients.transport.rest_client.RestClientTransport.decodeResponse(RestClientTransport.java:325)
    	at co.elastic.clients.transport.rest_client.RestClientTransport.getHighLevelResponse(RestClientTransport.java:295)
    	at co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:148)
    	at co.elastic.clients.elasticsearch.tasks.ElasticsearchTasksClient.get(ElasticsearchTasksClient.java:117)
    	at co.elastic.clients.elasticsearch.tasks.ElasticsearchTasksClient.get(ElasticsearchTasksClient.java:133)
    

    and the completed response json string should be something like this

    {
      "completed": true,
      "task": {
        "node": "xD7kSXXeSXWMURif3cX16w",
        "id": 2180131,
        "type": "transport",
        "action": "indices:admin/forcemerge",
        "description": "Force-merge indices [xxx], maxSegments[1], onlyExpungeDeletes[false], flush[true]",
        "start_time_in_millis": 1671621375383,
        "running_time_in_nanos": 9551767091603,
        "cancellable": false,
        "headers": {}
      },
      "response": {
        "_shards": {
          "total": 6,
          "successful": 6,
          "failed": 0
        }
      }
    }
    

    no response.batches exists however batches is force required in TaskStatus of the client code

    private TaskStatus(Builder builder) {
        this.batches = ApiTypeHelper.requireNonNull(builder.batches, this, "batches");
        ...
    }
    

    i think this a bug not related to https://github.com/elastic/elasticsearch-specification/issues/1767, so i opened this issue

    opened by AkisAya 1
Owner
elastic
elastic
Catogram - Experimental telegram client based on official Android sources

Catogram Experimental telegram client based on official Android sources Features: Message translator TGX Style of context menu VKUI Icons and inbuilt

null 188 Dec 17, 2022
Official React Native client for FingerprintJS PRO. 100% accurate device identification for fraud detection.

FingerprintJS PRO React Native Official React Native module for 100% accurate device identification, created for the FingerprintJS Pro Server API. Thi

FingerprintJS 26 Nov 22, 2022
EssentialClient is a client side mod originally forked from Carpet Client for 1.15.2 that implements new client side features

EssentialClient EssentialClient is a client side only mod originally forked from Carpet Client for 1.15.2 that implements new client side features. Th

null 62 Jan 3, 2023
mall学习教程,架构、业务、技术要点全方位解析。mall项目(40k+star)是一套电商系统,使用现阶段主流技术实现。涵盖了SpringBoot 2.3.0、MyBatis 3.4.6、Elasticsearch 7.6.2、RabbitMQ 3.7.15、Redis 5.0、MongoDB 4.2.5、Mysql5.7等技术,采用Docker容器化部署。

mall学习教程 简介 mall学习教程,架构、业务、技术要点全方位解析。mall项目(40k+star)是一套电商系统,使用现阶段主流技术实现。涵盖了SpringBoot 2.3.0、MyBatis 3.4.6、Elasticsearch 7.6.2、RabbitMQ 3.7.15、Redis 5

macro 11.7k Jan 8, 2023
mall-swarm是一套微服务商城系统,采用了 Spring Cloud Hoxton & Alibaba、Spring Boot 2.3、Oauth2、MyBatis、Docker、Elasticsearch、Kubernetes等核心技术,同时提供了基于Vue的管理后台方便快速搭建系统。mall-swarm在电商业务的基础集成了注册中心、配置中心、监控中心、网关等系统功能。文档齐全,附带全套Spring Cloud教程。

mall-swarm 友情提示 快速体验项目:在线访问地址。 全套学习教程:《mall学习教程》。 Spring Cloud全套教程:《SpringCloud学习教程》。 专属学习路线:学习不走弯路,整理了套非常不错的《mall专属学习路线》。 项目交流:想要加群交流项目的朋友,可以加入mall项目

macro 9.7k Jan 3, 2023
【咕泡学院实战项目】-基于SpringBoot+Dubbo构建的电商平台-微服务架构、商城、电商、微服务、高并发、kafka、Elasticsearch

咕泡商城- 微服务架构实战 咕泡商城是咕泡学院 Java架构课程中,帮助学员对于技术更好落地的一个实战项目,项目基于springboot2.1.6.RELEASE+Dubbo2.7.3 来构建微服务。 业务模块划分,尽量贴合互联网公司的架构体系。所以,除了业务本身的复杂度不是很高之外,整体的架构基本

Mic 4.5k Dec 26, 2022
🦄 开源社区系统:基于 SpringBoot + MyBatis + MySQL + Redis + Kafka + Elasticsearch + Spring Security + ... 并提供详细的开发文档和配套教程。包含帖子、评论、私信、系统通知、点赞、关注、搜索、用户设置、数据统计等模块。

Echo — 开源社区系统 项目上线到服务器之后可能会出现各种各样的 BUG,比如 Elasticsearch 服务启动失败导致搜索模块不可用,但是在本地运行是完全没问题的,所以各位小伙伴可以放心下载部署。 ?? 项目简介 Echo 是一套前后端不分离的开源社区系统,基于目前主流 Java Web

小牛肉 434 Jan 7, 2023
mall4cloud微服务商城,基于Spring Cloud、Nacos、Seata、Mysql、Redis、RocketMQ、canal、ElasticSearch、minio的B2B2C微服务商城系统,采用主流的互联网技术架构、全新的UI设计 B2B2C微服务商城|小程序微服务商城|

README 前言 本商城是基于Spring Cloud、Nacos、Seata、Mysql、Redis、RocketMQ、canal、ElasticSearch、minio的微服务B2B2C电商商城系统,采用主流的互联网技术架构、全新的UI设计、支持集群部署、服务注册和发现以及拥有完整的订单流程等

null 3k Jan 1, 2023
An example on how to build a configurable widget to trigger external searches along with Liferay search to Elasticsearch.

Liferay External Searches An example on how to build a configurable widget to trigger external searches along with Liferay search to Elasticsearch. Ge

Louis-Guillaume Durand 4 Oct 25, 2021
The IK Analysis plugin integrates Lucene IK analyzer into elasticsearch, support customized dictionary.

IK Analysis for Elasticsearch The IK Analysis plugin integrates Lucene IK analyzer (http://code.google.com/p/ik-analyzer/) into elasticsearch, support

Medcl 14.6k Jan 5, 2023
This application will help you to generate Elasticsearch template based on your data

Welcome to templates generator application for Elasticsearch This application will help you to generate the template and/or test index, based on your

DBeast 2 Jan 2, 2023
Reindex - application for visualize, optimize and automate your Elasticsearch reindex process

Welcome to reindex application for Elasticsearch This application will help you to reindex one or more existing indices, into the local or remote Elas

DBeast 3 Jan 2, 2023
Official Java library for the DeepL language translation API.

DeepL Java Library The DeepL API is a language translation API that allows other computer programs to send texts and documents to DeepL's servers and

DeepL 26 Dec 29, 2022
This is the official theme SDK for the FairPlayer Music Player for Android.

FairPlayer - Themes SDK This is the official theme SDK for the FairPlayer Music Player for Android. You can download the most recent version of FairPl

Mark Jivko 0 Jan 31, 2022
Patches for the old minecraft official launcher to add microsoft account support

MSA4Legacy Patches for the old minecraft official launcher to add microsoft account support My code here is quite atrocious in some parts (for example

Nep Nep 26 Nov 3, 2022
Official Quilt template mod.

Quilt Template Mod The official Quilt template Mod. You can use it as a template for your own mods! Usage In order to use this mod as a template: Crea

null 117 Jan 2, 2023
Official Quilt template mod.

Quilt Template Mod The official Quilt template Mod. You can use it as a template for your own mods! Usage In order to use this mod as a template: Crea

null 32 May 7, 2022
This is the src of Badlion client 3.0.0, The reason of this repo is badlion client's owner being p e d o

About Badlion Using Gradle instead of the shit mcp uwu Commands Run with random username gradle startGame Run with another username gradle startGame -

Pace 32 Dec 2, 2022
This is the src of Badlion client 3.0.0, The reason of this repo is badlion client's owner being p e d o

About Badlion Using Gradle instead of the shit mcp uwu Commands Run with random username gradle startGame Run with another username gradle startGame -

Pace 32 Dec 2, 2022