Suggester requires text when it shouldn't
Java API client version
7.17.2
Java version
17.0.2
Elasticsearch Version
7.17.2
Problem description
Per the documentation, the term suggester requires the search text to be set either per suggester, or globally. (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html#term-suggester)
Other suggesters, such as the completion suggester, do not require this at all. (https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters.html#querying)
However, the fluent interface requires this field to be set. For example:
new Suggester.Builder().suggesters("song-suggest", s -> s.completion(c->c.field("suggest")))
Results in a runtime exception The required text option is missing.
Specifying text to Suggester.Builder causes the exception to go away, but this changes the behavior if there are multiple suggesters that should use different texts (or prefixes, in the case of completion suggesters), so this is not a solution or workaround.
Update: the issue still exists in 7.17.5.
I cannot reproduce the issue in 7.17.5 and in 7.17.2. Here's the unit test used to check, in which I also included the term suggester since you mention it in the description:
@Test
public void i0254_suggesterTest() throws Exception {
new Suggester.Builder().suggesters("song-suggest", s -> s.completion(c->c.field("suggest"))).build();
new Suggester.Builder().suggesters("song-suggest", s -> s.term(c->c.field("suggest"))).build();
}
Can you check on your side?
Hi @swallez,
Thanks for taking a look at this issue!
It appears that I have been unclear in describing the issue. My apologies. The exception does not occur when building the Suggestion, but when a SearchRequest containing that Suggestion is sent to ES. I believe this to be an issue with the Java API, as ES is happy to accept an equivalent request via curl or the Kibana Dev Tool.
I will update the issue to hopefully make it more clear.
Hi @swallez,
I delved into it again, and I can only reproduce this issue if I do not specify a prefix for a completion suggestion. I think we only ever did that because of https://github.com/elastic/elasticsearch-java/issues/253. I don't think it actually makes sense to omit the prefix field, so I will close this issue and hope you will check out 253. :-)