Reputation: 175
I'm attempting to query a dynamic list of types in my ElasticSearch index using a NEST SearchRequest object.
public object Search(object runTimeData)
{
var request = new SearchRequest()
{
From = 0,
Size = 10
};
request = SetRouting(request, runTimeData);
request = SetIndices(request, runTimeData);
request = SetTypes(request, runTimeData);
request = SetQuery(request, runTimeData);
...
var results = _searchClient.Search<BaseOfAllTypes>(request);
return results;
}
...
private SearchRequest SetTypes(SearchRequest request, object runTimeData)
{
request.Types = GetTypesForRuntime(runTimeData);
}
If I call System.Text.Encoding.UTF8.GetString(_searchClient.Serializer.Serialize(request))
through my debugger on the line where I perform the search, I don't see anything relevant to types in the JSON:
{
"from": 0,
"size": 10,
"query": {
"bool": {
"must": [
{
"simple_query_string": {
"query": "my query data here",
"default_operator": "and"
}
}
]
}
}
}
The query results come back as though the types are being properly filtered, however. Running that generated JSON directly through elasticsearch-head returns results for all types, so it seems as though there's something that I'm not seeing in the serialization of the request that I really ought to see.
Upvotes: 2
Views: 493
Reputation: 6357
The "types" are present in the HTTP request header. What you're seeing is the HTTP request body. To get the request header, use
var requestHeader = results.ConnectionStatus.RequestUrl;
You'll also get the cluster address and index name information along with type information.
Beware, this works only when the Search()
operation succeeds. Otherwise results
can potentially be null
and this statement will throw an NPE.
Upvotes: 1