Reputation: 145
Code i am using to perform search against Elasticsearch
string q2 = "{\"query\":{\"bool\":{\"must\":[{\"fuzzy\":{\"name\":{\"value\":\"zeorgia\",\"max_expansions\":\"1\"}}}],\"must_not\":[],\"should\":[]}},\"from\":0,\"size\":50,\"sort\":[],\"aggs\":{ }}";
ISearchResponse<Responder> response2 = await _elasticClient.SearchAsync<Responder>(s => s.Query(qry => qry.Raw(q2))).ConfigureAwait(false);
Getting the below error
Invalid NEST response built from a unsuccessful (400) low level call on POST: /xyz-idx/_search?typed_keys=true
<Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>
<Response stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>
OriginalException = {"Request failed to execute. Call: Status code 400 from: POST /xyz-idx/_search?typed_keys=true. ServerError: Type: parsing_exception Reason: "unknown query [query]" CausedBy: "Type: named_object_not_found_exception Reason: "[1:19] unknown field [q...
Request failed to execute. Call: Status code 400 from: POST /xyz-idx/_search?typed_keys=true. ServerError: Type: parsing_exception Reason: "unknown query [query]" CausedBy: "Type: named_object_not_found_exception Reason: "[1:19] unknown field [query]""
Upvotes: 0
Views: 788
Reputation: 125488
The raw query should be the JSON object that would be assigned to the "query"
property i.e.
var searchResponse = client.Search<MyDocument>(s => s
.Index("index_name,cluster_two:index_name")
.Query(q => q
.Raw("{\"fuzzy\":{\"name\":{\"value\":\"bank\"}}}")
)
);
which would be equivalent to
var searchResponse = client.Search<MyDocument>(s => s
.Index("index_name,cluster_two:index_name")
.Query(q => q
.Fuzzy(f => f
.Field("name")
.Value("bank")
)
)
);
Upvotes: 1