elasticsearch-java icon indicating copy to clipboard operation
elasticsearch-java copied to clipboard

Fluent interface does not allow setting of prefix and completion for suggestions

Open d2a-jbroek opened this issue 3 years ago • 1 comments

Java API client version

7.17.2

Java version

17.0.2

Elasticsearch Version

7.17.2

Problem description

Per the ES documentation I want to specify a completion and prefix for suggestions: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html#querying

POST music/_search?pretty
{
  "suggest": {
    "song-suggest": {
      "prefix": "nir",        
      "completion": {         
          "field": "suggest"  
      }
    }
  }
}

In the fluent interface, I'd expect to be able to do something like this:

new Suggester.Builder().suggesters("song-suggest", s -> s.prefix("nir").completion(c->c.field("suggest")))

However, you can only use either prefix() or completion(), but not both. (The existence of FieldSuggester.Kind.Prefix suggests to me that "prefix" is incorrectly used as a type of suggester, rather than as a parameter for the completion suggester.)

The following does compile (and makes logical sense to me), however, it leads to a runtime exception:

new Suggester.Builder().suggesters("song-suggest", s -> s.completion(c->c.prefix("nir").field("suggest")))

The runtime exception in question:

co.elastic.clients.elasticsearch._types.ElasticsearchException: [es/search] failed: [x_content_parse_exception] [1:179] [completion] unknown field [prefix]

d2a-jbroek avatar Apr 26 '22 12:04 d2a-jbroek

Update: the issue still exists in 7.17.5.

d2a-jbroek avatar Jun 29 '22 12:06 d2a-jbroek

We're still forced to use the deprecated RHLC because of this bug (among others).

Due to the package collisions, that means we're still unable to use a version of Java later than Java 8.

To the maintainers: are you aware that you're blocking the technological modernisation of your consumers?

oliverlockwood avatar Apr 13 '23 14:04 oliverlockwood

Closing this as it was fixed in newer versions of the client, thanks for the feedback and sorry for the wait!

l-trotta avatar Feb 02 '24 16:02 l-trotta