elastic/elasticsearch-java

Deserialization of category context: wrong variant instance

valasatava opened this issue · 2 comments

Elasticsearch Version

8.9.1

Installed Plugins

No response

Java Version

20.0.2

OS Version

5.15.0-83-generic elastic/elasticsearch#92-Ubuntu SMP Mon Aug 14 09:30:42 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Problem Description

Using Java client:

<dependency>
     <groupId>co.elastic.clients</groupId>
     <artifactId>elasticsearch-java</artifactId>
     <version>8.10.3</version>
 </dependency>

Index is created following this example: https://www.elastic.co/guide/en/elasticsearch/reference/8.10/search-suggesters.html#context-suggester

{
  "mappings": {
    "properties": {
      "suggest": {
        "type": "completion",
        "contexts": [
          {                                 
            "name": "place_type",
            "type": "category"
          }
        ]
      }
    }
  }
}

category context is deserialized as geo

Screen Shot 2023-10-16 at 8 55 33 PM

Steps to Reproduce

Step 1: mappings

PUT place
{
  "mappings": {
    "properties": {
      "suggest": {
        "type": "completion",
        "contexts": [
          {                                 
            "name": "place_type",
            "type": "category"
          }
        ]
      }
    }
  }
}

Step 2: index creation

PUT place/_doc/1
{
  "suggest": {
    "input": [ "timmy's", "starbucks", "dunkin donuts" ],
    "contexts": {
      "place_type": [ "cafe" ]                    
    }
  }
}

Step 3: query

{
  "_source": {
    "includes": [
      "_none_"
    ]
  },
  "suggest": {
    "suggest": {
      "completion": {
        "field": "suggest",
        "size": 10,
        "contexts": {
          "place_type": [
            {
              "context": "cafe"
            }
          ]
        },
        "skip_duplicates": true
      }
    },
    "text": "tim"
  }
}

I expected https://javadoc.io/static/co.elastic.clients/elasticsearch-java/8.0.0/co/elastic/clients/elasticsearch/core/search/Context.Kind.html#Category, however the instance is of Location type

Screen Shot 2023-10-16 at 8 55 33 PM

Logs (if relevant)

No response

When I try this with a raw REST API request (for example, using the kibana dev-tools/console), I get the following:

"suggest": {
    "suggest": [
      {
        "text": "tim",
        "offset": 0,
        "length": 3,
        "options": [
          {
            "text": "timmy's",
            "_index": "place",
            "_id": "1",
            "_score": 1,
            "_source": {},
            "contexts": {
              "place_type": [
                "cafe"
              ]
            }
          }
        ]
      }
    ]
  }

There is nothing GeoLocation specific about the context place_type. I think there must be an issue with the java client you are using, and it is presumably trying to deduce more information from the name of the context. Perhaps the word place is being used to deduce a location? I think this issue should be moved to the java client repository because it does not appear to be an issue with elasticsearch.

Hello, thanks for the report! So, creating the mapping with the category context seems to work fine when creating the request using the java client builders:

esClient.indices().create(c ->c
    .index("test-category")
    .mappings(m -> m
        .properties("suggest", p -> p
            .completion(co -> co
                .contexts(cx -> cx
                    .type("category")
                    .name("place_type"))))));

But we might have problems with the json serialization, we'll investigate this!