Last active
April 16, 2024 14:07
-
-
Save EmmanuelDemey/093e924e7b53916516b5b55595bb2dd7 to your computer and use it in GitHub Desktop.
Correction Elasticsearch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
POST person-manu-v3/_search | |
{ | |
"size": 0, | |
"aggs": { | |
"group_by_year": { | |
"date_histogram": { | |
"field": "registered", | |
"calendar_interval": "1y" | |
}, | |
"aggs": { | |
"group_by_gender": { | |
"terms": { | |
"field": "gender" | |
} | |
}, | |
"avg_age": { | |
"avg": { | |
"field": "age" | |
} | |
}, | |
"filter_bucket_over_28": { | |
"bucket_selector": { | |
"buckets_path": { | |
"avgAge": "avg_age" | |
}, | |
"script": "params.avgAge > 28" | |
} | |
}, | |
"old_person": { | |
"top_hits": { | |
"_source": { | |
"includes": ["name", "age"] | |
}, | |
"size": 1, | |
"sort": [{ | |
"age": { "order": "desc"} | |
}] | |
} | |
} | |
} | |
}, | |
"highest_avg_age": { | |
"max_bucket": { | |
"buckets_path": "group_by_year>avg_age" | |
} | |
}, | |
"avg_age": { | |
"avg": { | |
"field": "age" | |
} | |
}, | |
"group_by_gender": { | |
"terms": { | |
"field": "gender" | |
}, | |
"aggs": { | |
"group_by_eyeColor": { | |
"filters": { | |
"filters": { | |
"blue": { | |
"term": { | |
"eyeColor": "blue" | |
} | |
}, | |
"brown": { | |
"term": { | |
"eyeColor": "brown" | |
} | |
} | |
} | |
} | |
}, | |
"group_by_registered": { | |
"date_histogram": { | |
"field": "registered", | |
"calendar_interval": "1y" | |
} | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DELETE person-manu | |
POST person-manu/_search | |
POST person-manu/_doc | |
{"isActive":false,"balance":"$3,961.21","picture":"http://placehold.it/32x32","age":23,"eyeColor":"brown","name":"Mattie Juarez","gender":"female","company":"TALKOLA","email":"[email protected]","phone":"+1 (889) 533-4000","address":"675 Moultrie Street, Northridge, Hawaii, 4439","about":"Esse incididunt do enim Lorem consequat. Exercitation et irure est veniam magna deserunt. Amet consectetur tempor nostrud dolor nisi dolor proident adipisicing. Aliqua incididunt nisi aliquip do est sint sint voluptate commodo deserunt ut culpa. Laborum eiusmod mollit eiusmod veniam commodo dolor tempor velit duis proident pariatur.\r\n","registered":"2020-02-05","location":{"lat":61.230241,"lon":96.685759},"tags":["voluptate","labore","duis","elit","ullamco","ex","nulla"],"friends":[{"id":0,"name":"Alta Fischer"},{"id":1,"name":"Edwards Hansen"},{"id":2,"name":"Yvette Evans"}]} | |
POST person-manu/_search | |
GET person-manu/_doc/Ygd7qI4BZ4wdy-XFi3yL | |
POST person-manu/_update/Ygd7qI4BZ4wdy-XFi3yL | |
{ | |
"doc": { | |
"age": 33 | |
} | |
} | |
GET person-manu/_doc/Ygd7qI4BZ4wdy-XFi3yL | |
DELETE person-manu/_doc/Ygd7qI4BZ4wdy-XFi3yL | |
GET person-manu/_doc/Ygd7qI4BZ4wdy-XFi3yL | |
POST person-manu/_bulk | |
{ "index": {}} | |
{"isActive":false,"balance":"$3,915.68","picture":"http://placehold.it/32x32","age":22,"eyeColor":"blue","name":"Reyes Mccullough","gender":"male","company":"UNI","email":"[email protected]","phone":"+1 (923) 457-3501","address":"810 Kane Place, Chestnut, Connecticut, 4745","about":"Sunt deserunt labore sunt nostrud ut ea. Nulla non aliquip voluptate duis deserunt eiusmod do incididunt reprehenderit anim incididunt aute. Nisi tempor excepteur minim commodo velit excepteur. Id officia officia consectetur anim.\r\n","registered":"2015-08-04","location":{"lat":76.988489,"lon":99.118051},"tags":["laboris","velit","deserunt","irure","adipisicing","sit","tempor"],"friends":[{"id":0,"name":"Marisa Noel"},{"id":1,"name":"Tucker Alvarado"},{"id":2,"name":"Dina Bradford"}]} | |
{ "index": {}} | |
{"isActive":true,"balance":"$2,925.94","picture":"http://placehold.it/32x32","age":36,"eyeColor":"blue","name":"Farrell Fletcher","gender":"male","company":"GAZAK","email":"[email protected]","phone":"+1 (830) 537-2053","address":"813 Christopher Avenue, Haena, Louisiana, 7863","about":"Excepteur culpa eu labore ad Lorem exercitation dolor quis in. Exercitation mollit fugiat amet proident minim est ad adipisicing ipsum. Fugiat ullamco incididunt occaecat ea eu ullamco ullamco. Ea quis culpa nulla aute nulla proident elit nostrud laboris elit ullamco laborum. Incididunt enim mollit enim do culpa eiusmod laboris Lorem dolore qui ad eu deserunt mollit. Id sint esse ea ullamco reprehenderit ut sit labore sunt quis aliquip eiusmod tempor. Tempor dolore quis do anim sit elit proident minim eu cillum occaecat nulla deserunt consectetur.\r\n","registered":"2015-08-02","location":{"lat":77.56049,"lon":115.554504},"tags":["commodo","proident","ut","excepteur","officia","deserunt","deserunt"],"friends":[{"id":0,"name":"Cote Barr"},{"id":1,"name":"June Mullen"},{"id":2,"name":"Rojas Rosario"}]} | |
POST person-manu/_search | |
POST _aliases | |
{ | |
"actions": [ | |
{ | |
"add": { | |
"index": "person-manu", | |
"alias": "male-manu", | |
"filter": { | |
"term": { | |
"gender": "male" | |
} | |
} | |
} | |
}, | |
{ | |
"add": { | |
"index": "person-manu", | |
"alias": "female-manu", | |
"filter": { | |
"term": { | |
"gender": "female" | |
} | |
} | |
} | |
} | |
] | |
} | |
GET /person-manu | |
GET /person-manu/_search | |
GET /male-manu/_search | |
GET /female-manu/_search | |
POST /person-manu/_search?q=name:reyes&size=2&sort=age:desc | |
{ | |
"_source": { | |
"includes": ["age", "name"] | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
POST _ingest/pipeline/_simulate | |
{ | |
"pipeline": { | |
"processors": [ | |
{ | |
"gsub": { | |
"field": "balance", | |
"pattern": ",", | |
"replacement": "" | |
} | |
}, | |
{ | |
"grok": { | |
"field": "balance", | |
"patterns": [ "%{NUMBER:balance:double}" ] | |
} | |
} | |
] | |
}, | |
"docs": [ | |
{ | |
"_source": { | |
"balance": "$3,915.68" | |
} | |
} | |
] | |
} | |
POST _ingest/pipeline/balance | |
{ | |
"processors": [ | |
{ | |
"gsub": { | |
"field": "balance", | |
"pattern": ",", | |
"replacement": "" | |
} | |
}, | |
{ | |
"grok": { | |
"field": "balance", | |
"patterns": [ | |
"%{NUMBER:balance:double}" | |
] | |
} | |
} | |
] | |
} | |
POST _reindex | |
{ | |
"source": { | |
"index": "person-manu-v3" | |
}, | |
"dest": { | |
"index": "person-manu-v4", | |
"pipeline": "balance" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET person-manu | |
Convert the location object into a geo_point object | |
POST _index_template/person-manu-template | |
{ | |
"index_patterns": [ | |
"person-manu*" | |
], | |
"template": { | |
"mappings": { | |
"properties": { | |
"about": { | |
"type": "text" | |
}, | |
"address": { | |
"type": "text" | |
}, | |
"age": { | |
"type": "long" | |
}, | |
"balance": { | |
"type": "text", | |
"fields": { | |
"keyword": { | |
"type": "keyword", | |
"ignore_above": 256 | |
} | |
} | |
}, | |
"company": { | |
"type": "text" | |
}, | |
"email": { | |
"type": "text", | |
"fields": { | |
"keyword": { | |
"type": "keyword", | |
"ignore_above": 256 | |
} | |
} | |
}, | |
"eyeColor": { | |
"type": "keyword" | |
}, | |
"friends": { | |
"properties": { | |
"id": { | |
"type": "long" | |
}, | |
"name": { | |
"type": "text", | |
"fields": { | |
"keyword": { | |
"type": "keyword", | |
"ignore_above": 256 | |
} | |
} | |
} | |
} | |
}, | |
"gender": { | |
"type": "keyword" | |
}, | |
"isActive": { | |
"type": "boolean" | |
}, | |
"location": { | |
"type": "geo_point" | |
}, | |
"name": { | |
"type": "text" | |
}, | |
"phone": { | |
"type": "keyword" | |
}, | |
"picture": { | |
"type": "text", | |
"index": false | |
}, | |
"registered": { | |
"type": "date", | |
"format": [ | |
"yyyy-MM-dd" | |
] | |
}, | |
"tags": { | |
"type": "text", | |
"fields": { | |
"keyword": { | |
"type": "keyword", | |
"ignore_above": 256 | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
POST _reindex | |
{ | |
"source": { | |
"index": "person-manu" | |
}, | |
"dest": { | |
"index": "person-manu-v3" | |
} | |
} | |
GET person-manu-v3 | |
GET _cat/indices?v | |
GET person-manu/_search | |
POST person-manu/_analyze | |
{ | |
"text": ["+1 (923) 457-3501"], | |
"field": "phone", | |
"explain": true | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
POST person-manu-v3/_search | |
{ | |
"size": 0, | |
"query": { | |
"term": { | |
"gender": "female" | |
} | |
} | |
} | |
POST person-manu-v3/_count | |
{ | |
"query": { | |
"term": { | |
"gender": "female" | |
} | |
} | |
} | |
POST person-manu-v3/_search | |
{ | |
"query": { | |
"constant_score": { | |
"filter": { | |
"term": { | |
"gender": { | |
"value": "female" | |
} | |
} | |
} | |
} | |
} | |
} | |
POST person-manu-v3/_search | |
{ | |
"_source": { | |
"includes": "age" | |
}, | |
"query": { | |
"range": { | |
"age": { | |
"gt": 30 | |
} | |
} | |
} | |
} | |
POST male-manu/_search | |
{ | |
"_source": { | |
"includes": "age" | |
}, | |
"query": { | |
"range": { | |
"age": { | |
"gt": 30 | |
} | |
} | |
} | |
} | |
POST person-manu-v3/_search | |
{ | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"range": { | |
"age": { | |
"gt": 30 | |
} | |
} | |
}, | |
{ | |
"term": { | |
"gender": { | |
"value": "male" | |
} | |
} | |
} | |
] | |
} | |
} | |
} | |
POST person-manu-v3/_search | |
{ | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"range": { | |
"age": { | |
"gt": 20 | |
} | |
} | |
}, | |
{ | |
"range": { | |
"balance": { | |
"gte": 2000, | |
"lte": 3000 | |
} | |
} | |
} | |
] | |
} | |
} | |
} | |
POST person-manu-v3/_search | |
{ | |
"query": { | |
"geo_distance": { | |
"distance": "1000km", | |
"location": { | |
"lat": 61.77596, | |
"lon": 94.52144 | |
} | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
POST _security/role/manu_role | |
{ | |
"indices": [ | |
{ | |
"names": ["person-manu-v4"], | |
"privileges": ["read"], | |
"query": { | |
"term": { | |
"gender": { | |
"value": "female" | |
} | |
} | |
}, | |
"field_security": { | |
"grant": ["*"], | |
"except": ["age"] | |
} | |
} | |
] | |
} | |
POST _security/user/decathlon-manu | |
{ | |
"password": "decathlon", | |
"roles": ["manu_role"] | |
} | |
POST /person-manu-v4/_search |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment