%%%%% Page 7: Index API %%%%% curl -X PUT "127.0.0.1:9200/$(whoami)_actors" curl -X PUT "127.0.0.1:9200/$(whoami)_movies" curl -X GET "localhost:9200/_all?pretty" curl -X GET "localhost:9200/_cat/indices?v&pretty" curl -I "localhost:9200/$(whoami)_actors?pretty" %%%%% Page 8: Index API %%%%% curl -X POST "localhost:9200/$(whoami)_actors/_close?pretty" curl -X POST "localhost:9200/$(whoami)_actors/_open?pretty" curl -X GET "localhost:9200/$(whoami)_actors/_settings?pretty" curl -X GET "localhost:9200/$(whoami)_actors/_stats?pretty" curl -X PUT "localhost:9200/$(whoami)_actors/_alias/$(whoami)_czechactors?pretty" curl -X DELETE "localhost:9200/$(whoami)_actors,$(whoami)_movies" %%%%% Page 10: Example: Mappings curl -X PUT "localhost:9200/$(whoami)_actors?pretty" -H 'Content-Type: application/json' -d "{ \"mappings\": { \"properties\": { \"name\": { \"properties\" : { \"first\" : {\"type\" : \"text\"}, \"last\" : {\"type\" : \"text\"} } }, \"year\": { \"type\": \"integer\", \"index\": true } } }, \"aliases\": { \"$(whoami)_actors1966\": { \"filter\": { \"term\": { \"year\": 1966 } } } } }" curl -X PUT "localhost:9200/$(whoami)_actors/_mapping?pretty" -H 'Content-Type: application/json' -d '{ "properties": { "movies": { "type": "keyword" } } }' curl -X GET "localhost:9200/$(whoami)_actors/_mapping?pretty" curl -X PUT "127.0.0.1:9200/$(whoami)_movies" %%%%% Page 11: Document API: Index %%%%% curl -X PUT "127.0.0.1:9200/$(whoami)_actors/_doc/trojan?pretty" -H "Content-Type: application/json" -d '{ "name": { "first": "Ivan", "last": "Trojan" }, "year": 1964, "movies": [ "samotari", "medvidek", "karamazovi" ] }' %%%%% Page 13: Example: GET %%%%% curl -X GET "localhost:9200/$(whoami)_actors/_doc/sverak?_source=name.first,year&pretty" curl -X GET "localhost:9200/$(whoami)_actors/_source/machacek/?_source_excludes=year&pretty" curl -I "localhost:9200/$(whoami)_actors/_doc/trojan" curl -I "localhost:9200/$(whoami)_movies/_source/zelary" curl -X GET "localhost:9200/_mget?pretty" -H 'Content-Type: application/json' -d "{ \"docs\": [ { \"_index\": \"$(whoami)_actors\", \"_id\": \"trojan\" }, { \"_index\": \"$(whoami)_actors\", \"_id\": \"machacek\" } ] }" curl -X GET "localhost:9200/_mget?pretty" -H 'Content-Type: application/json' -d "{ \"docs\": [ { \"_index\": \"$(whoami)_actors\", \"_id\": \"trojan\" }, { \"_index\": \"$(whoami)_movies\", \"_id\": \"zelary\" } ] }" curl -X GET "localhost:9200/$(whoami)_movies/_mget?pretty" -H 'Content-Type: application/json' -d '{ "ids" : ["medvidek", "zelary", "kolja"] }' %%%%% Page 15: Example: Update %%%%% curl -X POST "localhost:9200/$(whoami)_movies/_update/medvidek?pretty" -H 'Content-Type: application/json' -d '{ "script" : "ctx._source.remove(\u0027year\u0027)" }' curl -X POST "localhost:9200/$(whoami)_movies/_update/medvidek?pretty" -H 'Content-Type: application/json' -d '{ "script" : { "source": "ctx._source.rating += params.increment", "lang": "painless", "params" : { "increment" : 10 } }, "upsert": { "counter": 1 } }' curl -X POST "localhost:9200/$(whoami)_movies/_update_by_query?pretty" -H 'Content-Type: application/json' -d '{ "script": { "source": "ctx._source.rating++", "lang": "painless" }, "query": { "term": { "year": 2000 } } }' %%%%% Page 17: Example: Delete %%%%% curl -X DELETE "localhost:9200/$(whoami)_actors/_doc/geislerova?pretty" curl -X POST "localhost:9200/$(whoami)_actors/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "name.last": "Vilhelmova" } } }' curl -X POST "localhost:9200/$(whoami)_actors,$(whoami)_movies/_delete_by_query?pretty" -H 'Content-Type: application/json' -d '{ "query": { "range" : { "year" : { "gte" : 2008 } } } }' %%%%% Page 18: Document API: Bulk %%%%% curl -s -H "Content-Type: application/x-ndjson" -XPOST localhost:9200/_bulk --data-binary "@bulk.txt"; %%%%% Page 19: Document API: Reindex %%%%% curl -X POST "localhost:9200/_reindex?pretty" -H "Content-Type: application/json" -d "{ \"source\": { \"index\": \"$(whoami)_actors\", \"query\": { \"range\" : { \"year\" : { \"gte\" : 1970 } } } }, \"dest\": { \"index\": \"$(whoami)_youngactors\" } }" %%%%% Page 22: Match All, Match None %%%%% curl -X GET "localhost:9200/$(whoami)_actors/_search?filter_path=hits.hits._source&pretty" -H 'Content-Type: application/json' -d '{ "query" : { "match_all" : { } } , "from" : 2, "size" : 2, "_source" : [ "name", "year" ], "sort" : { "year" : { "order" : "asc" } } }' curl -X GET "localhost:9200/$(whoami)_actors1966/_search?filter_path=hits.hits._source&pretty" -H 'Content-Type: application/json' -d '{ "query" : { "match_all" : { } } , "_source" : [ "name", "year" ] }' curl -X GET "localhost:9200/$(whoami)_actors1966/_search?filter_path=hits.hits._source&pretty" -H 'Content-Type: application/json' -d '{ "query" : { "match_none" : { } } }' %%%%% Page 24: Example: Full Text Queries %%%%% curl -X GET "localhost:9200/$(whoami)_actors/_search?pretty" -H 'Content-Type: application/json' -d '{ "query": { "match": { "name.first" : "Ivan" } } }' curl -X GET "localhost:9200/$(whoami)_*/_search?pretty" -H 'Content-Type: application/json' -d '{ "query": { "multi_match": { "query" : "medvidek", "fields": ["title.cs", "movies"] } } }' curl -X GET "localhost:9200/$(whoami)_actors/_search?pretty" -H 'Content-Type: application/json' -d '{ "query": { "query_string": { "query": "Jiri OR Ivan", "default_field": "name.first" } } }' curl -X POST "localhost:9200/$(whoami)_movies/_search?pretty" -H 'Content-Type: application/json' -d '{ "query": { "intervals" : { "text" : { "all_of" : { "intervals" : [ { "match" : { "query" : "vztah" } }, { "match" : { "query" : "poetický" } } ], "ordered": false } } } } }' %%%%% Page 26: Example: Term-level queries %%%%% curl -X GET "localhost:9200/$(whoami)_movies/_search?pretty" -H 'Content-Type: application/json' -d '{ "query": { "exists": { "field": "actors" } } }' curl -X GET "localhost:9200/$(whoami)_actors/_search?pretty" -H 'Content-Type: application/json' -d '{ "query": { "ids" : { "values" : ["machacek", "trojan", "schneiderova"] } } }' curl -X GET "localhost:9200/$(whoami)_actors/_search?pretty" -H 'Content-Type: application/json' -d '{ "query": { "prefix": { "movies": { "value": "med" } } } }' curl -X GET "localhost:9200/$(whoami)_*/_search?pretty" -H 'Content-Type: application/json' -d '{ "query": { "range": { "year": { "gte": 1970, "lte": 1980 } } } }' %%%%% Page 28: Example: Compound Queries %%%%% curl -X POST "localhost:9200/$(whoami)_actors/_search?pretty" -H 'Content-Type: application/json' -d '{ "query": { "bool" : { "must" : { "term" : { "movies" : "medvidek" } }, "must_not" : { "term" : { "movies" : "karamazovi" } }, "filter" : { "range" : { "year" : { "gte" : 1960, "lte" : 1978 } } }, "should" : [ { "term" : { "movies" : "samotari" } }, { "term" : { "movies" : "kolja" } } ] } } }' curl -X GET "localhost:9200/$(whoami)_actors/_search?pretty" -H 'Content-Type: application/json' -d '{ "query": { "boosting": { "positive": { "match": { "name.first": "Jiri" } }, "negative": { "range" : { "year" : { "gte" : 1960 } } }, "negative_boost": 0.0 } } }' %%%%% Page 29: Example: Compoung Queries %%%%% curl -X GET "localhost:9200/$(whoami)_actors/_search?pretty" -H 'Content-Type: application/json' -d '{ "query": { "function_score": { "query": { "match_all": {} }, "boost": "5", "functions": [ { "filter": { "match": { "name.first": "Jiri" } }, "weight": 30 }, { "filter": { "match": { "movies": "medvidek" } }, "random_score": {}, "weight": 10 }, { "filter": { "match": { "movies": "samotari" } }, "random_score": {}, "weight": 10 }, { "filter": { "match": { "movies": "vratnelahve" } }, "random_score": {}, "weight": 10 } ], "max_boost": 500, "score_mode": "sum", "boost_mode": "avg", "min_score": 5 } } }' %%%%% Page 30: Aggregations %%%%% curl -X POST "localhost:9200/$(whoami)_actors/_search?size=0&pretty" -H 'Content-Type: application/json' -d '{ "aggs": { "minYear": { "min": { "field": "year" } }, "maxYear": { "max": { "field": "year" } }, "aveYear": { "avg": { "field": "year" } }, "sumYear": { "sum": { "field": "year" } }, "values": { "value_count": { "field": "year" } } } }' %%%%% Page 31: Aggregations %%%%% curl -X GET "localhost:9200/$(whoami)_actors/_search?pretty" -H 'Content-Type: application/json' -d '{ "size": 0, "aggs": { "actorsInMovies": { "terms": { "field": "movies" } } } }' %%%%% Page 32: Exercise 1 %%%%% curl -X GET "localhost:9200/$(whoami)_actors/_search?filter_path=hits.hits._source&pretty" -H 'Content-Type: application/json' -d '{ "query": { "query_string": { "query": "(Jiri OR Ivan) AND movies:(medvidek AND samotari)", "default_field": "name.first" } },"_source" : [ "name", "movies" ] }' %%%%% Page 33: Exercise 2 %%%%% curl -X POST "localhost:9200/$(whoami)_actors/_search?size=0&pretty" -H 'Content-Type: application/json' -d' { "aggs": { "playsInMedvidek": { "filter": { "term": { "movies": "medvidek" } }, "aggs": { "averageYear": { "avg": { "field": "year" } } } } } }' curl -X POST "localhost:9200/$(whoami)_actors/_search?size=0&pretty" -H 'Content-Type: application/json' -d' { "size": 0, "query": { "match": { "movies": "medvidek" } }, "aggs": { "averageYear": { "avg" : { "field": "year" } } } }' curl -X POST "localhost:9200/$(whoami)_actors/_search?pretty" -H 'Content-Type: application/json' -d' { "size" : 0, "aggs": { "playsInMedvidek": { "filter": { "term": { "movies": "medvidek" } }, "aggs": { "averageYear": { "avg": { "field": "year" } } } } } }' %%%%% Page 34: Exercise 3 %%%%% curl -X POST "localhost:9200/$(whoami)_movies/_search?filter_path=hits.hits._source&pretty" -H 'Content-Type: application/json' -d '{ "query" : { "bool" : { "must" : { "exists" : { "field" : "director" } }, "must_not" : {"match" : { "genres" : "romance" } }, "filter" : { "range" : { "year" : { "gte" : 2000, "lte" : 2006 } } }, "should" : [ { "term" : { "genres" : "drama" } }, { "term" : { "genres" : "comedy" } } ] } }, "_source" : [ "title" ], "sort" : { "rating" : { "order" : "desc" }, "year" : { "order" : "asc" } } }' %%%%% Page 35: Exercise 4 %%%%% curl -X POST "localhost:9200/$(whoami)_movies/_search?filter_path=hits.hits._source&pretty" -H 'Content-Type: application/json' -d '{ "query": { "intervals" : { "text" : { "all_of" : { "intervals" : [ { "match" : { "query" : "vztah" } }, { "any_of" : { "intervals" : [ { "match" : { "query" : "milenec" } }, { "match" : { "query" : "vyvíjet" } } ] } } ], "ordered" : true } } } }, "_source" : [ "title", "text" ], "sort" : { "title.cs.keyword" : { "order" : "desc" } } }' %%%%% Delete indices %%%%% curl -X DELETE "localhost:9200/$(whoami)_*"