I am trying to search for a text in elasticsearch using nest 7.10.1. I want to search in two different indexes, I get a response in the form of documents, but I cannot access its properties because the result has the combination of two indexes. Below is the code I tried. Both the indexes has same properties. What do I use in the foreach loop to access the key and values of the result documents.
public void searchIndices(string query) {
var response = client.Search<object>(
s => s.Index("knowledgearticles_index, index2")
.Query(q => q.Match(m => m.Field("locationName")
.Query(query))));
Console.WriteLine(response.Documents);
foreach(object r in response.Documents) {
}
}
I am using elasticsearch 7.10.2
If the two indices that you're searching over contain different JSON structures, then the
TinSearch<T>will need to be a type that the differing JSON structures can be deserialize to.objectwill work as per the example in your question, but then there is no typed access for any of the properties.A simple approach to overcoming this is to hook up the
JsonNetSerializerand then useJObjectforTWe now have a way of accessing properties on
JObject, but will still need to handle the type of each property.