Installation
Install NEST via Visual Studio's Package Manager Console.
Install-Package NEST
Connecting
To connect you will need your cluster URL and your API key. You can get both of these from your Facetflow Control Panel's Connection Details page.
The API key will serve as the username for the connection, so you will need to configure your URI like this:
var uri = new Uri("https://apikey:@account.region.cloud.facetflow.io");
Now we can go ahead and create the client connection. We'll set the default index as well as a convenience.
var settings = new ConnectionSettings(uri).SetDefaultIndex("my_index");
var client = new ElasticClient(settings);
Indexing
Index a document by calling the Index
method with your model. We'll refresh the index after this so you can search for your document immediately. Manually refreshing the index is only recommended for testing purposes since it has performance implications.
var post = new Post
{
Id = 1,
User = "me",
PostDate = DateTime.Now,
Message = "trying out facetflow"
};
client.Index(post);
client.Refresh();
Searching
Now you can search for your document using NEST's fluent query syntax.
var result = client.Search(s => s
.Index("my_index")
.Query(q =>
q.QueryString(qs =>
qs.Query("trying out facetflow")))
.Filter(f => f.Term(t => t.User, "me")));
With basic indexing and search working, feel free to dive into more details on the NEST API and the Elasticsearch API in their respective official guides.