Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] getFieldMapping throws UnexpectedJsonEventException #587

Closed
hendryluk opened this issue Jul 31, 2023 · 3 comments
Closed

[BUG] getFieldMapping throws UnexpectedJsonEventException #587

hendryluk opened this issue Jul 31, 2023 · 3 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@hendryluk
Copy link

hendryluk commented Jul 31, 2023

What is the bug?

getFieldMapping() throws UnexpectedJsonEventException if no mappings match the field name.

How can one reproduce the bug?

  1. OpenSearch client with httpclient5 transport:
OpenSearchTransport transport = ApacheHttpClient5TransportBuilder.builder(HttpHost.create(url)).build();
OpenSearchClient client = new OpenSearchClient(transport);
  1. getFieldMapping:
client.indices().getFieldMapping(m -> m.index("my-index").fields("my-field"));

What is the expected behavior?

Should return GetFieldMappingResponse with empty mappings, which is what's returned by the REST endpoint:

GET /my-index/_mapping/field/my-field -> HTTP 200:

{
    "my-index": {
        "mappings": {}
    }
}

Actual behavior

Throws UnexpectedJsonEventException:

org.opensearch.client.json.UnexpectedJsonEventException: Unexpected JSON event 'END_OBJECT' instead of 'KEY_NAME'
        at org.opensearch.client.json.JsonpUtils.expectEvent(JsonpUtils.java:71)
        at org.opensearch.client.json.JsonpUtils.expectNextEvent(JsonpUtils.java:65)
        at org.opensearch.client.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:161)
        at org.opensearch.client.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:150)
        at org.opensearch.client.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:88)
        at org.opensearch.client.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:92)
        at org.opensearch.client.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:56)
        at org.opensearch.client.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:85)
        at org.opensearch.client.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:189)
        at org.opensearch.client.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:150)
        at org.opensearch.client.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:88)
        at org.opensearch.client.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:92)
        at org.opensearch.client.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:56)
        at org.opensearch.client.transport.endpoints.DictionaryResponse.lambda$setupDictionaryResponseDeserializer$0(DictionaryResponse.java:161)
        at org.opensearch.client.json.ObjectDeserializer.parseUnknownField(ObjectDeserializer.java:218)
        at org.opensearch.client.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:187)
        at org.opensearch.client.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:150)
        at org.opensearch.client.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:88)
        at org.opensearch.client.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:92)
        at org.opensearch.client.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:56)
        at org.opensearch.client.transport.httpclient5.ApacheHttpClient5Transport.decodeResponse(ApacheHttpClient5Transport.java:602)
        at org.opensearch.client.transport.httpclient5.ApacheHttpClient5Transport.prepareResponse(ApacheHttpClient5Transport.java:491)
        at org.opensearch.client.transport.httpclient5.ApacheHttpClient5Transport.lambda$performRequestAsync$0(ApacheHttpClient5Transport.java:162)
        at java.base/java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:642)
        at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:506)
        at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2073)
        at org.opensearch.client.transport.httpclient5.ApacheHttpClient5Transport$1.completed(ApacheHttpClient5Transport.java:198)
        at org.opensearch.client.transport.httpclient5.ApacheHttpClient5Transport$1.completed(ApacheHttpClient5Transport.java:191)
        at org.apache.hc.core5.concurrent.BasicFuture.completed(BasicFuture.java:123)
        at org.apache.hc.core5.concurrent.ComplexFuture.completed(ComplexFuture.java:72)
        at org.apache.hc.client5.http.impl.async.InternalAbstractHttpAsyncClient$1$1.completed(InternalAbstractHttpAsyncClient.java:280)
        at org.apache.hc.core5.http.nio.support.AbstractAsyncResponseConsumer$1.completed(AbstractAsyncResponseConsumer.java:101)
        at org.apache.hc.core5.http.nio.entity.AbstractBinAsyncEntityConsumer.completed(AbstractBinAsyncEntityConsumer.java:84)
        at org.apache.hc.core5.http.nio.entity.AbstractBinDataConsumer.streamEnd(AbstractBinDataConsumer.java:81)
        at org.apache.hc.core5.http.nio.support.AbstractAsyncResponseConsumer.streamEnd(AbstractAsyncResponseConsumer.java:142)
        at org.apache.hc.client5.http.impl.async.HttpAsyncMainClientExec$1.streamEnd(HttpAsyncMainClientExec.java:251)
        at org.apache.hc.core5.http2.impl.nio.ClientH2StreamHandler.consumeData(ClientH2StreamHandler.java:239)
        at org.apache.hc.core5.http2.impl.nio.AbstractH2StreamMultiplexer$H2Stream.consumeData(AbstractH2StreamMultiplexer.java:1636)
        at org.apache.hc.core5.http2.impl.nio.AbstractH2StreamMultiplexer.consumeDataFrame(AbstractH2StreamMultiplexer.java:1045)
        at org.apache.hc.core5.http2.impl.nio.AbstractH2StreamMultiplexer.consumeFrame(AbstractH2StreamMultiplexer.java:734)
        at org.apache.hc.core5.http2.impl.nio.AbstractH2StreamMultiplexer.onInput(AbstractH2StreamMultiplexer.java:445)
        at org.apache.hc.core5.http2.impl.nio.AbstractH2IOEventHandler.inputReady(AbstractH2IOEventHandler.java:65)
        at org.apache.hc.core5.http2.impl.nio.ClientH2IOEventHandler.inputReady(ClientH2IOEventHandler.java:39)
        at org.apache.hc.core5.reactor.ssl.SSLIOSession.decryptData(SSLIOSession.java:600)
        at org.apache.hc.core5.reactor.ssl.SSLIOSession.access$200(SSLIOSession.java:74)
        at org.apache.hc.core5.reactor.ssl.SSLIOSession$1.inputReady(SSLIOSession.java:202)
        at org.apache.hc.core5.reactor.InternalDataChannel.onIOEvent(InternalDataChannel.java:142)
        at org.apache.hc.core5.reactor.InternalChannel.handleIOEvent(InternalChannel.java:51)
        at org.apache.hc.core5.reactor.SingleCoreIOReactor.processEvents(SingleCoreIOReactor.java:178)
        at org.apache.hc.core5.reactor.SingleCoreIOReactor.doExecute(SingleCoreIOReactor.java:127)
        at org.apache.hc.core5.reactor.AbstractSingleCoreIOReactor.execute(AbstractSingleCoreIOReactor.java:86)
        at org.apache.hc.core5.reactor.IOReactorWorker.run(IOReactorWorker.java:44)
        at java.base/java.lang.Thread.run(Thread.java:829)

What is your host/environment?

Client:

  • MacOS, Ventura 13.4.1
  • jdk 11.0.20-amzn
  • org.opensearch.client:opensearch-java:2.6.0

Server:

  • AWS OpenSearch Service v2.5.0

Do you have any screenshots?

(See exception stack-trace above)

Do you have any additional context?

Add any other context about the problem.

@hendryluk hendryluk added bug Something isn't working untriaged labels Jul 31, 2023
@wbeckler wbeckler removed the untriaged label Aug 3, 2023
@saimedhi
Copy link

saimedhi commented Aug 9, 2023

I've reproduced the bug using both ApacheHttpClient5Transport and RestClientTransport and observed the same issue. When trying to access a non-existent field mapping using the URL https://localhost:9200/my-index/_mapping/field/my-field, RestClientTransport returns an empty mapping ({ "my-index": { "mappings": {} } }), while ApacheHttpClient5Transport throws an UnexpectedJsonEventException. This variance in behavior can be attributed to the differing strictness levels of response parsing between the two clients.

@wbeckler wbeckler added the good first issue Good for newcomers label Sep 19, 2023
@MikePieperSer
Copy link
Contributor

The java class for TypeFieldMappings is buggy.
When we look at the JSON:

{
  "indexName": {
    "mappings": {
      "field1": {
        "full_name": "field1",
        "mapping": {
          "field1": {
            "type": "text",
            "store": true,
            "analyzer": "my_analyzer",
            "position_increment_gap": 10,
            "term_vector": "with_positions_offsets"
          }
        }
      },
      "field3": {
        "full_name": "field3",
        "mapping": {
          "field3": {
            "type": "text",
            "store": true,
            "analyzer": "this_analyzer",
            "position_increment_gap": 10,
            "term_vector": "with_positions_offsets"
          }
        }
      },
      "field2": {
        "full_name": "field2",
        "mapping": {
          "field2": {
            "type": "text",
            "store": true,
            "analyzer": "another_analyzer",
            "position_increment_gap": 10,
            "term_vector": "with_positions_offsets"
          }
        }
      }
    }
  }
}

Then we see that under "mappings" must be a map from field name to field information. But TypeFieldMappings has only one element. (I found commit 702e185 where it was changed from a map to a single element).

The error message means that it expected the end of the object, but it sees another key-name (in this example "field3").

A fix for this problem will change the java-client API. I have an PR for this.

@VachaShah
Copy link
Collaborator

Done via #641

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

5 participants