Elastic Search Query

Hi!!

I am using Elasticsearch _plugin/head i.e., “http://localhost:9200/_plugin/head/”

default port for elasticsearch is 9200

Creating index:

Index is a collection of different type of documents and document properties.
POST http://localhost:9200/check_index

Response:
{“acknowledged”: true}

Adding data:
PUT http://localhost:9200/_search/basics/sampledocs/1/
{
“name”: “a”,
“city”: “delhi”,
“age”: 15
}

Response:

“_index”: “check_index”,
“_type”: “check_type”,
“_id”: “1”,
“_version”: 1,
“_shards”: {
“total”: 2,
“successful”: 1,
“failed”: 0
},
“created”: true

Deleting index:
POST http://localhost:9200/check_index

Response
{“acknowledged”: true}

The URI of the request was /check_index/check_type/1. It’s important to understand the parameters here:

check_index is the index of the data in Elasticsearch.
check_type is the type.
1 is the id of our entry.

AGGREGATION:

Avg Aggregation:
This aggregation is used to get the average of any numeric field present in the aggregated documents. For example,

POST http://localhost:9200/tweets/tweet_data/_search/

Request Body:
{
“size”: 0,
“aggs”: {
“distinct_name”: {
“avg”: {
“field”: “user_listed_count”
}}}}

Response Body:

“aggregations”: {
“distinct_name”: {
“value”: 64.69687162891046
}}

Cardinality Aggregation:

This aggregation gives the count of distinct values of a particular field. For example,

Request Body:

“size”: 0,
“aggs”: {
“distinct_name”: {
“cardinality”: {
“field”: “user_listed_count”
}}}}

Response body:

“aggregations”: {
“distinct_name”: {
“value”: 12
}}

Sum Aggregation:

This aggregation calculates the sum of a specific numeric field in aggregated documents.

Request Body:

{
“size”: 0,
“aggs”: {
“distinct_name”: {
“sum”: {
“field”: “user_listed_count”
}}}}
Response body:

“aggregations”: {
“distinct_name”: {
“value”: 119948
}}

Extended Stats Aggregation:

This aggregation generates all the statistics about a specific numerical field in aggregated documents. For example,

Request Body:
{
“size”: 0,
“aggs”: {
“_stats”: {
“extended_stats”: {
“field”: “user_listed_count”
}}}}

Response Body:

“aggregations”: {
“_stats”: {
“count”: 1854,
“min”: 0,
“max”: 626,
“avg”: 64.69687162891046,
“sum”: 119948,
“sum_of_squares”: 65034276,
“variance”: 30892.13357165882,
“std_deviation”: 175.76158161458042,
“std_deviation_bounds”: {
“upper”: 416.2200348580713,
“lower”: -286.8262916002504
}}}

Thanks.

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s