Basic of elasticsearch go to https://www.elastic.co/
Chrome plugin for elasticsearch: Go to add extention and search for sense
Enable debug of NEST lib:
Create elasticClient from following code:
var node = new Uri(nodeUrl);
var settings = new ConnectionSettings(node).DefaultIndex(index).DisableDirectStreaming()
.OnRequestCompleted(details =>
{
Debug.WriteLine("### ES REQEUST ###");
if (details.RequestBodyInBytes != null) Debug.WriteLine(Encoding.UTF8.GetString(details.RequestBodyInBytes));
Debug.WriteLine("### ES RESPONSE ###");
if (details.ResponseBodyInBytes != null) Debug.WriteLine(Encoding.UTF8.GetString(details.ResponseBodyInBytes));
}).PrettyJson();
elasticClient = new ElasticClient(settings);
Nest.ISearchResponse<DataModel.Position> searchResponse = new Nest.SearchResponse<DataModel.Position>();
int[] units = Array.ConvertAll(unitFilter.Split(','), c => int.Parse(c));
//Query using Search Descriptor
var sd = new SearchDescriptor<DataModel.Position>();
sd.Query(q => q.Range(r => r.Field(f => f.EventCount).GreaterThan(0)) && q.Terms(t => t.Field(f => f.UnitId).Terms<int>(units)))
.Sort(s => s.Descending(d => d.DeviceTime))
.From(paging.From)
.Take(paging.Take).Size(20);
searchResponse = elasticClient.Search<DataModel.Position>(sd);
//Query of elastic search after var jsonBody = Encoding.UTF8.GetString(searchResponse.ApiCall.RequestBodyInBytes);
return searchResponse.Hits.ToList().Select(s => s.Source);
Book on ES : https://drive.google.com/open?id=0B--gpA0TMqR1dVZfbXJrb2ZIWnM
Basic Query to monitor elasticsearch and index
//Query for order by desc record
POST http://192.168.0.110:9200/satelocgconnect/position/_search?pretty=true
{
"size": 10,
"sort": [
{
"deviceTime": {
"order": "desc"
}
}
]
}
//Query to get top 10 record
GET http://192.168.0.110:9200/runtimeunits/unitrunTime/_search?pretty=true
{
"size": 10
}
//To know node state
GET http://192.168.0.110:9200/_nodes/stats/indices/fielddata?level=indices&fields=*
//To know index health doc count etc
GET http://192.168.0.110:9200/_cat/indices?v
//to check all alias
GET http://192.168.0.110:9200/*/_alias
//to check cluster health
GET http://192.168.0.110:9200/_cluster/health
//to get mapping of index
GET http://192.168.0.110:9200/runtimeunits/_mapping
//create thread with number_of_replicas and number_of_shards
PUT http://192.168.0.110:9200/runtimeunits_v1/
{
"settings" : {
"index" : {
"number_of_shards" : 2,
"number_of_replicas" :1
}
}
}
// delte index
DELETE http://192.168.0.110:9200/runtimeunits
//close index
POST http://192.168.0.16:9200/analyticalgconnect_v1/_close
//add alias name to index
POST http://192.168.0.110:9200/_aliases/
{
"actions" : [
{ "remove" : { "index" : "runtimeunits_v1", "alias" : "runtimeunits" } }
{ "add" : { "index" : "runtimeunits", "alias" : "runtimeunits" } }
]
}
Chrome plugin for elasticsearch: Go to add extention and search for sense
Enable debug of NEST lib:
Create elasticClient from following code:
var node = new Uri(nodeUrl);
var settings = new ConnectionSettings(node).DefaultIndex(index).DisableDirectStreaming()
.OnRequestCompleted(details =>
{
Debug.WriteLine("### ES REQEUST ###");
if (details.RequestBodyInBytes != null) Debug.WriteLine(Encoding.UTF8.GetString(details.RequestBodyInBytes));
Debug.WriteLine("### ES RESPONSE ###");
if (details.ResponseBodyInBytes != null) Debug.WriteLine(Encoding.UTF8.GetString(details.ResponseBodyInBytes));
}).PrettyJson();
elasticClient = new ElasticClient(settings);
Nest.ISearchResponse<DataModel.Position> searchResponse = new Nest.SearchResponse<DataModel.Position>();
int[] units = Array.ConvertAll(unitFilter.Split(','), c => int.Parse(c));
//Query using Search Descriptor
var sd = new SearchDescriptor<DataModel.Position>();
sd.Query(q => q.Range(r => r.Field(f => f.EventCount).GreaterThan(0)) && q.Terms(t => t.Field(f => f.UnitId).Terms<int>(units)))
.Sort(s => s.Descending(d => d.DeviceTime))
.From(paging.From)
.Take(paging.Take).Size(20);
searchResponse = elasticClient.Search<DataModel.Position>(sd);
//Query of elastic search after var jsonBody = Encoding.UTF8.GetString(searchResponse.ApiCall.RequestBodyInBytes);
return searchResponse.Hits.ToList().Select(s => s.Source);
Book on ES : https://drive.google.com/open?id=0B--gpA0TMqR1dVZfbXJrb2ZIWnM
Basic Query to monitor elasticsearch and index
//Query for order by desc record
POST http://192.168.0.110:9200/satelocgconnect/position/_search?pretty=true
{
"size": 10,
"sort": [
{
"deviceTime": {
"order": "desc"
}
}
]
}
//Query to get top 10 record
GET http://192.168.0.110:9200/runtimeunits/unitrunTime/_search?pretty=true
{
"size": 10
}
//To know node state
GET http://192.168.0.110:9200/_nodes/stats/indices/fielddata?level=indices&fields=*
//To know index health doc count etc
GET http://192.168.0.110:9200/_cat/indices?v
//to check all alias
GET http://192.168.0.110:9200/*/_alias
//to check cluster health
GET http://192.168.0.110:9200/_cluster/health
//to get mapping of index
GET http://192.168.0.110:9200/runtimeunits/_mapping
//create thread with number_of_replicas and number_of_shards
PUT http://192.168.0.110:9200/runtimeunits_v1/
{
"settings" : {
"index" : {
"number_of_shards" : 2,
"number_of_replicas" :1
}
}
}
// delte index
DELETE http://192.168.0.110:9200/runtimeunits
//close index
POST http://192.168.0.16:9200/analyticalgconnect_v1/_close
//add alias name to index
POST http://192.168.0.110:9200/_aliases/
{
"actions" : [
{ "remove" : { "index" : "runtimeunits_v1", "alias" : "runtimeunits" } }
{ "add" : { "index" : "runtimeunits", "alias" : "runtimeunits" } }
]
}
Comments
Post a Comment