Skip to content

Instantly share code, notes, and snippets.

@piranha
Last active July 27, 2021 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piranha/b50e5ff1d6e9772bdd30a6196aa7e491 to your computer and use it in GitHub Desktop.
Save piranha/b50e5ff1d6e9772bdd30a6196aa7e491 to your computer and use it in GitHub Desktop.
:headers = <<
Content-Type: application/json
#
# what indices are there
GET http://localhost:9200/_cat/indices
# delete product
DELETE http://localhost:9200/product
# index products
POST http://localhost:9200/product/_bulk
:headers
{ "index":{ "_id": 1 } }
{ "title":"One", "val": 1}
{ "index":{ "_id": 2 } }
{ "title":"Two", "val": 1}
{ "index":{ "_id": 3 } }
{ "title":"Three", "val": 1}
{ "index":{ "_id": 4 } }
{ "title":"Four", "val": 2}
{ "index":{ "_id": 5 } }
{ "title":"Five", "val": 2}
# delete coll
DELETE http://localhost:9200/coll
# coll schema
PUT http://localhost:9200/coll
:headers
{
"mappings": {
"properties": {
"items": {"type": "nested"}
}
}
}
# index stuff in coll
POST http://localhost:9200/coll/_doc/1
:headers
{
"items": [
{"id": "3", "srt": 1},
{"id": "1", "srt": 2},
{"id": "4", "srt": 3}
]
}
# anything in coll?
GET http://localhost:9200/coll/_search?pretty
:headers
# search by id
GET http://localhost:9200/coll/_search?pretty
:headers
{
"query": {
"terms": {
"_id": ["1"]
}
}
}
# terms lookup
# it's not possible to sort by data in coll :(
POST http://localhost:9200/product/_search?pretty
:headers
{
"query": {
"terms": {
"_id": {
"index": "coll",
"id": "1",
"path": "items.id"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment