Skip to content

Instantly share code, notes, and snippets.

@gustavoapolinario
Last active February 4, 2020 14:01
Show Gist options
  • Save gustavoapolinario/8843228a5ef69f6fd05700010d3941bb to your computer and use it in GitHub Desktop.
Save gustavoapolinario/8843228a5ef69f6fd05700010d3941bb to your computer and use it in GitHub Desktop.
Rest Elasticsearch samples
GET /_analyze?analyzer=standard&text=22+march+be+with+yoiu+(I+am+your+father)
GET /_analyze?analyzer=portuguese&text=Música
POST /index/type/_bulk
{"create": {}}
{"field": "value", "field2": "value2"}
{"create": {}}
{"field": "value", "field2": "value2"}
PUT /catalogo_v3
{
"settings": {
"index": {
"number_of_shards": 3,
"number_of_replicas": 0
},
"analysis": {
"filter": {
"portuguese_stop": {
"type": "stop",
"stopwords": "_portuguese_"
},
"portuguese_stemmer": {
"type": "stemmer",
"language": "light_portuguese"
},
"filtro_de_sinonimos": {
"type": "synonym",
"synonyms": [
"futebol => futebol,society",
"society => society,futebol",
"volei,voleibol,volleyball",
"esport => esport,futebol,society,volei,basquet",
"exat => exat,matematic,fisic,computaca",
"arte => arte,pintur,teatr,music,cinem"
]
}
},
"analyzer": {
"sinonimos": {
"tokenizer": "standard",
"filter": [
"lowercase",
"portuguese_stop",
"portuguese_stemmer",
"filtro_de_sinonimos"
]
}
}
}
},
"mappings": {
"pessoas": {
"_all": {
"type": "string",
"index": "analyzed",
"analyzer": "portuguese"
},
"properties": {
"cidade": {
"type": "string",
"index": "analyzed",
"analyzer": "portuguese"
},
"estado": {
"type": "string"
},
"formação": {
"type": "string",
"index": "analyzed",
"analyzer": "portuguese"
},
"interesses": {
"type": "string",
"index": "analyzed",
"analyzer": "portuguese",
"search_analyzer": "sinonimos"
},
"nome": {
"type": "string",
"index": "analyzed",
"analyzer": "portuguese"
},
"país": {
"type": "string",
"index": "analyzed",
"analyzer": "portuguese"
}
}
}
}
}
DELETE /index/type/id
DELETE /people/person/1
GET /<index>/<type>/_count
GET /people/person/_count
Response:
{
"count": 1,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
}
}
GET /<index>/<type>/<id>
GET /people/person/1
Response
{
"_index": "people",
"_type": "person",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"name" : "Bruce wayne",
...
}
}
GET /_cat/indices?v
GET /_cat/indices/twi*?v&s=index
Response
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open twitter u8FNjxh8Rfy_awN11oDKYQ 1 1 1200 0 88.1kb 88.1kb
green open twitter2 nYFWZEO7TUiOjLQXBaYJpA 1 0 0 0 260b 260b
GET /index/_mapping
GET /people/_mapping
Inside map, you can salve the original for search and a new modified by analyser
"name": {
"type": "string",
"fields": {
"original": {
"type": "string",
"index": "not_analyzed"
}
},
"index": "analyzed",
"analyzer": "portuguese"
}
POST /people/person
POST /catalogo/pessoas/1
Body
{
"name" : "Bruce wayne",
"interests" : ["dark", "bat", "fight"],
"city" : "São Paulo",
"state" : "SP",
"country" : "Brasil"
}
PUT /people/_settings
Body
{
"index" : {
"number_of_replicas" : 0
}
}
PUT /catalogo_v2
{
"settings": {
"index": {
"number_of_shards": 3,
"number_of_replicas": 0
}
},
"mappings": {
"pessoas_v2": {
"_all": {
"type": "string",
"index": "analyzed",
"analyzer": "portuguese"
},
"properties": {
"cidade": {
"type": "string",
"index": "analyzed",
"analyzer": "portuguese"
},
"estado": {
"type": "string"
},
"formação": {
"type": "string",
"index": "analyzed",
"analyzer": "portuguese"
},
"interesses": {
"type": "string",
"index": "analyzed",
"analyzer": "portuguese"
},
"nome": {
"type": "string",
"index": "analyzed",
"analyzer": "portuguese"
},
"país": {
"type": "string",
"index": "analyzed",
"analyzer": "portuguese"
}
}
}
}
}
GET /<index>/<type>/_search
GET /people/person/_search
GET /people/person/_search?q=bat
GET /people/person/_search?q=interests:bat
GET /people/person/_search?q=interests:bat&city:Paulo
GET /people/person/_search?q=bat&size=50&from=10
GET /people/person/_search?q=_all:bat
/catalogo_v2/pessoas/_search?q=bat+AND+fight
Response
{
"took": 11,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "people",
"_type": "person",
"_id": "E1Zp3AVK9Z-g4VXH09ly",
"_score": 1,
"_source": {
...
}
},
...
]
}
}
GET /index/_mapping/type
GET /people/_mapping/person
Response
{
"people": {
"mappings": {
"person": {
"properties": {
"city": {
"type": "string"
},
...
}
}
}
}
}
HEAD /index/type/id
HEAD /people/person/1
PUT /index/_mapping/type
PUT /people/_mapping/person
{
"properties": {
"number": {
"type": "integer"
}
}
}
POST /people/person/1/_update
Body
{
"doc": {
"name": "Clark Kent"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment