Am learning to use ElasticSearch with Nest as the .Net client. While indexing the data, I don't have a defined model (type mapping) to write the index to, I rely on ElasticSearch to create that for me
Creating the client
var settings = new ConnectionSettings(_config.Uri);
settings.DefaultIndex(_config.defaultIndexName);
_client = new ElasticClient(settings);
Indexing data by Type info
public void Index(object data)
{
var response = _client.Index(data, d => d.Type(data.GetType().Name));
if (!response.IsValid)
{
throw new InvalidOperationException(response.DebugInformation);
}
}
Say if the data type was Project
class with some properties
class Project
{
int Id {get; set;}
string Name {get; set;}
}
How do I query the above indexed data. Please bear in mind that the indexing part and the search/query part are completely isolated parts of the system and they are not aware of each other, so at search time, maximum I can get is the name of type 'Project' being queried but not its internal fields details. So, How can I run the search query in ElasticSearch as its fluent API would need to be something like this
_client.Search<Project>(...)
but I want something generic like
_client.Search('project', ...)
Thanks