Description
Elastic.Clients.Elasticsearch version: 8.15.2
Elasticsearch version: 8.15.0
.NET runtime version: .NET 8
Operating system version: Windows 10
Description of the problem including expected versus actual behavior:
When using the SearchRequest with a FieldSuggester, where the Text property is set, the ElasticsearchClient sends a request with the text field not set in the correct place. The server then responds with a parsing error.
This is an example of an invalid generated suggester:
"suggest": {
"0": {
"term": {
"analyzer": "term_search_analyzer",
"field": "term",
"prefix_length": 2,
"size": 10,
"sort": "score",
"text": "elastic"
}
}
}
The "term" object does not support the field "text", so therefore the server returns with a parsing exception.
Steps to reproduce:
- Create a new SearchRequest object.
- In the SearchRequest, set the Suggest property with a new Suggester containing a Suggester dictionary.
- Inside the dictionary, add a TermSuggester, with the "Text" property set to any string.
- Send the request with the Search API
Expected behavior
The client should generate a valid request, where the "text" property is next to the "term" property.
"suggest": {
"0": {
"text": "elastic",
"term": {
"analyzer": "term_search_analyzer",
"field": "term",
"prefix_length": 2,
"size": 10,
"sort": "score"
}
}
}
Provide DebugInformation
(if relevant):
# FailureReason: BadResponse while attempting POST on http://127.0.0.1:9200/wiviosug/_search?typed_keys=true
# Audit trail of this API call:
- [1] BadResponse: Node: http://127.0.0.1:9200/ Took: 00:00:00.2604276
# OriginalException: Elastic.Transport.TransportException: Request failed to execute. Call: Status code 400 from: POST /wiviosug/_search?typed_keys=true. ServerError: Type: parsing_exception Reason: "suggester[term] doesn't support field [text]"
at Elastic.Transport.DistributedTransport`1.HandleTransportException(RequestData data, Exception clientException, TransportResponse response)
at Elastic.Transport.DistributedTransport`1.FinalizeResponse[TResponse](RequestData requestData, RequestPipeline pipeline, List`1 seenExceptions, TResponse response)
at Elastic.Transport.DistributedTransport`1.RequestCoreAsync[TResponse](Boolean isAsync, HttpMethod method, String path, PostData data, RequestParameters requestParameters, OpenTelemetryData openTelemetryData, CancellationToken cancellationToken)
at Elastic.Clients.Elasticsearch.ElasticsearchClient.<>c__DisplayClass28_0`3.<<DoRequestCoreAsync>g__SendRequest|0>d.MoveNext() in /_/src/Elastic.Clients.Elasticsearch/Client/ElasticsearchClient.cs:line 158
--- End of stack trace from previous location ---
# Request:
{"query":{"bool":{"must":{"match":{"term.completion":{"query":"test"}}},"should":{"rank_feature":{"field":"doc_frequency"}}}},"size":10,"_source":{"includes":["term"]},"suggest":{"0":{"term":{"analyzer":"term_search_analyzer","field":"term","prefix_length":2,"size":10,"sort":"score","text":"elastic"}},"1":{"term":{"analyzer":"term_search_analyzer","field":"term","prefix_length":2,"size":10,"sort":"score","text":"search"}},"2":{"term":{"analyzer":"term_search_analyzer","field":"term","prefix_length":2,"size":10,"sort":"score","text":"test"}}}}
# Response:
{"error":{"root_cause":[{"type":"parsing_exception","reason":"suggester[term] doesn't support field [text]","line":1,"col":292}],"type":"parsing_exception","reason":"suggester[term] doesn't support field [text]","line":1,"col":292},"status":400}
# Exception:
Elastic.Transport.TransportException: Request failed to execute. Call: Status code 400 from: POST /wiviosug/_search?typed_keys=true. ServerError: Type: parsing_exception Reason: "suggester[term] doesn't support field [text]"
at Elastic.Transport.DistributedTransport`1.HandleTransportException(RequestData data, Exception clientException, TransportResponse response)
at Elastic.Transport.DistributedTransport`1.FinalizeResponse[TResponse](RequestData requestData, RequestPipeline pipeline, List`1 seenExceptions, TResponse response)
at Elastic.Transport.DistributedTransport`1.RequestCoreAsync[TResponse](Boolean isAsync, HttpMethod method, String path, PostData data, RequestParameters requestParameters, OpenTelemetryData openTelemetryData, CancellationToken cancellationToken)
at Elastic.Clients.Elasticsearch.ElasticsearchClient.<>c__DisplayClass28_0`3.<<DoRequestCoreAsync>g__SendRequest|0>d.MoveNext() in /_/src/Elastic.Clients.Elasticsearch/Client/ElasticsearchClient.cs:line 158
--- End of stack trace from previous location ---