Description
Java API client version
8.1.1
Java version
11
Elasticsearch Version
8.1.0
Problem description
I try to execute a search requesting a term-suggester:
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"analyzer": "full_analyzer",
"fields": [
"searchText^1",
"searchTextBoosted^4.0",
],
"operator": "and",
"query": "Stabi",
"type": "cross_fields"
}
}
]
}
},
"from": 0,
"size": 20,
"sort": [
{
"_score": {
"order": "desc"
}
}
],
"suggest": {
"name.suggest": {
"term": {
"field": "searchTextBoosted",
"suggest_mode": "missing"
}
},
"text": "Stabi"
}
}
The result looks good:
{
"took": 10,
"timed_out": false,
"_shards": {
"total": 3,
"successful": 3,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 2,
"relation": "eq"
},
"max_score": 3.4410129,
"hits": [
{
"_index": "my-index",
"_id": "BP-xtn8BLc_6fF5-zBDh",
"_score": 3.4410129,
"_source": {
// stuff ...
}
}
]
},
"suggest": {
"term#name.suggest": [
{
"text": "stabi",
"offset": 0,
"length": 5,
"options": [
{
"text": "stab",
"score": 0.75,
"freq": 2
},
{
"text": "stand",
"score": 0.6,
"freq": 2
}
]
},
{
"text": "stab",
"offset": 0,
"length": 5,
"options": []
}
]
}
}
But the Java Client is not happy, because it thinks that the "options"-field in the term-suggester's result should be an object rather than an array. This causes the following error:
co.elastic.clients.json.UnexpectedJsonEventException: Unexpected JSON event 'START_ARRAY' instead of '[START_OBJECT, KEY_NAME]' at co.elastic.clients.json.JsonpUtils.ensureAccepts(JsonpUtils.java:103) ~[elasticsearch-java-8.1.1.jar:?]
This is probably due to the code-generation that this library uses. I think that the specification is incorrect.
Looking at the options of a completion-suggester (https://github.com/elastic/elasticsearch-specification/blob/7b8304b279b50f87239c0d83262a1f0fd2963a2a/specification/_global/search/_types/suggester.ts#L51):
export class CompletionSuggest<TDocument> extends SuggestBase {
options: CompletionSuggestOption<TDocument>[]
}
And looking at the options of a term-suggester (https://github.com/elastic/elasticsearch-specification/blob/7b8304b279b50f87239c0d83262a1f0fd2963a2a/specification/_global/search/_types/suggester.ts#L65):
export class TermSuggest extends SuggestBase {
options: TermSuggestOption
}
This looks wrong, the result that elasticsearch returns is clearly an Array of options.
PS: PhraseSuggest looks wrong too (https://github.com/elastic/elasticsearch-specification/blob/7b8304b279b50f87239c0d83262a1f0fd2963a2a/specification/_global/search/_types/suggester.ts#L58):
export class PhraseSuggest extends SuggestBase {
options: PhraseSuggestOption
}
Cheers
Lukas