Skip to content

Instantly share code, notes, and snippets.

@russcam russcam/Example.cs
Last active Aug 10, 2018

Embed
What would you like to do?
// Using NEST 6.2.0 with NEST.JsonNetSerializer 6.2.0
private static void Main()
{
var defaultIndex = "documents";
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var connectionSettings = new ConnectionSettings(pool, new InMemoryConnection(), (builtin, settings) =>
new JsonNetSerializer(builtin, settings, contractJsonConverters: new JsonConverter[] { new StringEnumConverter() }))
.DefaultIndex(defaultIndex)
.DisableDirectStreaming()
.PrettyJson()
.OnRequestCompleted(callDetails =>
{
if (callDetails.RequestBodyInBytes != null)
{
Console.WriteLine(
$"{callDetails.HttpMethod} {callDetails.Uri} \n" +
$"{Encoding.UTF8.GetString(callDetails.RequestBodyInBytes)}");
}
else
{
Console.WriteLine($"{callDetails.HttpMethod} {callDetails.Uri}");
}
Console.WriteLine();
if (callDetails.ResponseBodyInBytes != null)
{
Console.WriteLine($"Status: {callDetails.HttpStatusCode}\n" +
$"{Encoding.UTF8.GetString(callDetails.ResponseBodyInBytes)}\n" +
$"{new string('-', 30)}\n");
}
else
{
Console.WriteLine($"Status: {callDetails.HttpStatusCode}\n" +
$"{new string('-', 30)}\n");
}
});
var client = new ElasticClient(connectionSettings);
var doc = new MyDocument(1)
{
Polygon = new PolygonGeoShape(new[] {
new[]
{
new GeoCoordinate(1, 2),
new GeoCoordinate(3, 4)
}
})
};
client.IndexDocument(doc);
}
public class MyDocument
{
public MyDocument(int id) => Id = id;
public int Id { get; set; }
public PolygonGeoShape Polygon { get; set; }
}
/*
outputs
PUT http://localhost:9200/documents/mydocument/1?pretty=true
{
"id": 1,
"polygon": {
"coordinates": [
[
[
2.0,
1.0
],
[
4.0,
3.0
]
]
],
"type": "polygon"
}
}
Status: 200
------------------------------
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.