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

Deserialization of category context: wrong variant instance #691

Open
valasatava opened this issue Oct 17, 2023 · 2 comments
Open

Deserialization of category context: wrong variant instance #691

valasatava opened this issue Oct 17, 2023 · 2 comments
Labels
Category: Bug Something isn't working

Comments

@valasatava
Copy link

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

@valasatava valasatava added Category: Bug Something isn't working needs:triage labels Oct 17, 2023
@craigtaverner
Copy link

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.

@craigtaverner craigtaverner transferred this issue from elastic/elasticsearch Oct 17, 2023
@craigtaverner craigtaverner reopened this Oct 17, 2023
@l-trotta
Copy link
Contributor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants