GET kibana_sample_data_flights/_mapping GET kibana_sample_data_ecommerce/_mapping GET kibana_sample_data_logs/_mapping GET mytime34/_mapping
POST kibana_sample_data_flights/_search { "query": { "match_all": {} }, "track_total_hits": true } POST kibana_sample_data_ecommerce/_search { "query": { "match_all": {} }, "track_total_hits": true } POST kibana_sample_data_logs/_search { "query": { "match_all": {} }, "track_total_hits": true }
#将域值为string类型,并且域名是string开头的定义为text PUT mydynamictemplateindex-1/ { "mappings": { "dynamic_templates": [ { "strings_as_ip": { "match_mapping_type": "string", "match": "string*", "mapping": { "type": "text" } } } ] } }
POST mydynamictemplateindex-1/_doc { "string_1":"abc", "non-string-prefix":"dfd" }
GET mydynamictemplateindex-1/_mapping
PUT mydynamictemplateindex-2/ { "mappings": { "dynamic_templates": [ { "strings_as_ip": { "match_mapping_type": "*", "mapping": { "type": "{dynamic_type}" } } } ] } }
POST mydynamictemplateindex-2/_doc { "string_1":"1990-12-23", "non-string-prefix":"dfd", "number_1": 3 }
GET mydynamictemplateindex-2/_mapping
PUT mydynamictemplateindex-3/ { "mappings": { "dynamic_templates": [ { "strings_as_ip": { "match_mapping_type": "string", "match": "ip*", "runtime": { "type": "keyword" } } } ] } }
POST mydynamictemplateindex-3/_doc { "string_1":"1990-12-23", "ipsdf":"dfd", "number_1": 3 }
GET mydynamictemplateindex-3/_mapping
start ----Define and use an ingest pipeline that satisfies a given set of requirements, including the use of Painless to modify documents---
PUT enrichindex { "mappings": { "properties": { "DestAirportID":{ "type": "keyword" } } } }
POST enrichindex/_doc { "DestAirportID": "SYD" } POST enrichindex/_doc { "DestAirportID": "VE05" }
#定义一个enrich policy PUT /_enrich/policy/my-policy-1 { "match": { "indices": ["kibana_sample_data_flights"], "match_field": "DestAirportID", "enrich_fields": ["FlightDelayType", "OriginCountry", "DistanceKilometers", "DestLocation", "Carrier"] } }
PUT /_enrich/policy/my-policy-1/_execute?wait_for_completion=true
PUT _ingest/pipeline/my-pipeline-1 { "description" : "use enrich processor rich data", "processors" : [ { "enrich": { "policy_name": "my-policy-1", "field": "DestAirportID", "target_field": "mynewdata" } } ] }
POST /_ingest/pipeline/my-pipeline-1/_simulate { "docs": [ { "_index": "index", "_id": "id", "_source": { "DestAirportID": "SYD", "abc":"dfd" } }, { "_index": "index", "_id": "id", "_source": { "DestAirportID": "VE05", "abc":"dfd" } } ] }
POST enrichindex/_doc?pipeline=my-pipeline-1 { "DestAirportID": "SYD" }
GET enrichindex/_search
GET enrichindex/_mapping
POST enrichindex/_doc { "DestAirportID": "SYD" }
PUT _ingest/pipeline/script-pipeline { "description": "sdf", "processors": [ { "script": { "lang": "painless", "source": "ctx['Carrier'] = "abc";\nctx['FlightDelayType'] = "efg";" } } ] }
POST /_ingest/pipeline/script-pipeline/_simulate { "docs": [ { "_index": "index", "_id": "id", "_source": { "Carrier": "sdf", "FlightDelayType":"sdfsdf" } }, { "_index": "index", "_id": "id", "_source": { "foo": "rab" } } ] }
POST enrichindex/_doc?pipeline=script-pipeline { "DestAirportID": "SYD" }
POST enrichindex/_search
end ---- Define and use an ingest pipeline that satisfies a given set of requirements, including the use of Painless to modify documents---
PUT longindex { "mappings": { "properties": { "product": { "type": "long" } } } }
POST longindex/_doc { "product": 4 }
PUT doubleindex { "mappings": { "properties": { "product": { "type": "double" } } } }
POST doubleindex/_doc { "product": 7.0 }
POST longindex,doubleindex/_search { "query": {"match_all": {}}, "sort": [ { "product": { "order": "desc", "numeric_type": "long" } } ] }
#如果mapping中有排序字段 而文档中没有这个字段也不会报错 POST longindex,doubleindex/_search { "query": {"match_all": {}}, "sort": [ { "abc": { "missing" : "_last", "order": "desc", "unmapped_type": "long" } } ] }
PUT multivaluesindex { "mappings": { "properties": { "product": { "type": "long" }, "@timestamp": { "type": "date" } } } }
POST multivaluesindex/_doc { "@timestamp": 1591890612001, "product":[1,9] } POST multivaluesindex/_doc { "@timestamp": 1591890612001, "product":[2,7] }
POST multivaluesindex/_search { "query": { "match_all": {} }, "sort": [ { "product": { "order": "asc", "mode": "avg" } } ] }
POST multivaluesindex/_search { "query": { "match_all": {} }, "sort": [ { "_script": { "type": "number", "script": { "lang": "painless", "source": "doc['product'].get(1) * params.factor", "params": { "factor": 3 } }, "order": "asc" } } ] }
PUT nestedindex { "mappings": { "properties": { "product": { "type": "nested" }, "@timestamp": { "type": "date" } } } }
POST nestedindex/_doc { "@timestamp": 1591890612000, "product": [ { "price": 1, "color": "yellow" }, { "price": 5, "color": "red" } ] } POST nestedindex/_doc { "@timestamp": 1591890612001, "product": [ { "price": 2, "color": "yellow" }, { "price": 4, "color": "red" } ] } POST nestedindex/_search
POST nestedindex/_search { "query": { "match_all": {} }, "sort": [ { "product.price": { "mode": "min", "order": "asc", "nested": { "path": "product", "filter": { "match": { "product.color": "yellow red" } } } } } ] }
PUT nestednestedindex { "mappings": { "properties": { "product": { "type": "nested", "properties": { "company":{ "type":"nested" } } }, "@timestamp": { "type": "date" } } } }
POST nestednestedindex/_doc { "@timestamp": 1591890612000, "product": [ { "price": 1, "color": "yellow", "company": [ { "name": "a", "age": 44 }, { "name": "b", "age": 22 } ] }, { "price": 5, "color": "red", "company": [ { "name": "b", "age": 55 }, { "name": "c", "age": 11 } ] } ] } POST nestednestedindex/_doc { "@timestamp": 1591890612000, "product": [ { "price": 1, "color": "yellow", "company": [ { "name": "a", "age": 66 }, { "name": "b", "age": 11 } ] }, { "price": 5, "color": "red", "company": [ { "name": "b", "age": 44 }, { "name": "c", "age": 0 } ] } ] } POST nestednestedindex/_search { "query": { "match_all": {} }, "sort": [ { "product.company.age": { "mode": "min", "order": "desc", "nested": { "path": "product", "filter": { "match": { "product.color": { "query":"yellow red"
}
}
},
"nested": {
"path": "product.company",
"filter": {
"match": {
"product.company.name": "b"
}
}
}
}
}
}
] }
GET kibana_sample_data_ecommerce/_search { "from": 0, "size": 20, "query": { "match": { "customer_full_name": { "query": "Eddie Underwood", "operator": "and" } } } }
POST /kibana_sample_data_flights/_pit?keep_alive=5m
GET /_search { "size": 10000, "query": { "match_all": {} }, "pit": { "id": "n_XoAwEaa2liYW5hX3NhbXBsZV9kYXRhX2ZsaWdodHMWRmJGNGxCMDRRc3VZcXYydVV6NnkwQQAWUjFqaFRIaENRM2VYeTVxRHJRS1pPQQAAAAAAAABIvhZmOEZoMmctMlJYcTFVTnFobWNzb3Z3AAEWRmJGNGxCMDRRc3VZcXYydVV6NnkwQQAA", "keep_alive": "5m" }, "sort": [ { "timestamp": { "order": "asc", "format": "strict_date_optional_time_nanos" } }, { "_shard_doc": "desc" } ] }
GET /_search { "size": 10000, "query": { "match_all": {} }, "pit": { "id": "n_XoAwEaa2liYW5hX3NhbXBsZV9kYXRhX2ZsaWdodHMWRmJGNGxCMDRRc3VZcXYydVV6NnkwQQAWUjFqaFRIaENRM2VYeTVxRHJRS1pPQQAAAAAAAABIvhZmOEZoMmctMlJYcTFVTnFobWNzb3Z3AAEWRmJGNGxCMDRRc3VZcXYydVV6NnkwQQAA", "keep_alive": "5m" }, "sort": [ { "timestamp": { "order": "asc", "format": "strict_date_optional_time_nanos" } }, { "_shard_doc": "desc" } ], "search_after": [ "2024-02-25T23:50:12.000Z", 13020 ] }
DELETE /_pit { "id" : "n_XoAwEaa2liYW5hX3NhbXBsZV9kYXRhX2ZsaWdodHMWRmJGNGxCMDRRc3VZcXYydVV6NnkwQQAWUjFqaFRIaENRM2VYeTVxRHJRS1pPQQAAAAAAAABMzxZmOEZoMmctMlJYcTFVTnFobWNzb3Z3AAEWRmJGNGxCMDRRc3VZcXYydVV6NnkwQQAA" }
GET /_nodes/stats/indices/search
POST kibana_sample_data_ecommerce/_search?size=1
PUT _scripts/my-search-template { "script": { "lang": "mustache", "source": { "{{my_query}}": { "match": { "{{field_name}}":{ "query": "{{query_string}}", "operator":"{{operator}}" } } }, "from": "{{from}}", "size": "{{size}}" }, "params": { "query_string": "My query string" } } }
POST _render/template { "id": "my-search-template", "params": { "my_query":"query", "field_name":"category", "query_string": "Men's Clothing", "operator": "AND", "from": 0, "size": 10 } }
GET kibana_sample_data_ecommerce/_search/template { "id": "my-search-template", "params": { "my_query":"query", "field_name":"category", "query_string": "Men's Clothing", "operator": "AND", "from": 0, "size": 10 } }
POST _aliases { "actions": [ { "add": { "index": "mytime34", "alias": "my-alias1212" } } ] }
POST my-alias1212/_search
GET mytime34/_alias
GET _alias
GET kibana_sample_data_ecommerce/_mapping
POST kibana_sample_data_ecommerce/_search { "query": {"term": { "customer_first_name.keyword": { "value": "Rabbia Al" } }} }
POST _reindex? { "source": { "index": "kibana_sample_data_ecommerce", "query": {"term": { "customer_first_name.keyword": { "value": "Rabbia Al" } }} }, "dest": { "index": "new-kibana_sample_data_ecommerce" } }
POST _reindex? { "source": { "index": "kibana_sample_data_ecommerce", "query": { "match": { "customer_full_name": "Rabbia Al Ruiz" } } }, "dest": { "index": "new-kibana_sample_data_ecommerce" } }
#查看新的索引中的数据 POST new-kibana_sample_data_ecommerce/_search { "query": {"match_all": {}} }
POST new-kibana_sample_data_ecommerce/_update_by_query? { "script": { "source": "ctx._source.products[0].base_price=100000", "lang": "painless" }, "query": { "match": { "category": "Men's Shoes" } } } #查看新的索引中的数据 POST new-kibana_sample_data_ecommerce/_search? { "query": {"match_all": {}}, "sort": [ { "products.base_price": { "order": "desc" } } ] }
PUT _index_template/template-for-data-stream { "index_patterns":["mydatastream*"], "priority": 2, "template": { "settings": { "number_of_shards": 3, "number_of_replicas": 2, "refresh_interval": "1s" }, "mappings": { "properties": { "@timestamp": { "type": "date" }, "content": { "type": "text" }, "text": { "type": "text" } } }, "aliases": { "my_alias11111": {} } }, "data_stream": {} }
POST mydatastrea456/_doc/ { "text": "dfddd thed request", "@timestamp": "1591890612000", "content":"ce" }
POST my_alias11111/_search { "query": {"match_all": {}} }
POST /_index_template/_simulate_index/template-for-data-stream
POST /_index_template/_simulate/template-for-data-stream
GET kibana_sample_data_ecommerce/_mapping GET kibana_sample_data_ecommerce/_search?size=1
POST /kibana_sample_data_ecommerce/_async_search? { "size": 0, "sort": [ { "order_date": { "order": "asc" } } ], "aggs": { "taxful_total_price_sum": { "sum": { "field": "taxful_total_price" } } } }
start------------------------------------ Backup and restore a cluster and/or specific indices ---------------------------
GET _snapshot/mysnapshot1/my_snapshot1/_status
POST /_snapshot/mysnapshot1/my_snapshot1/_restore?wait_for_completion=true { "indices": "mytime345", "ignore_unavailable": true, "include_global_state": true, "rename_pattern": "mytime345", "rename_replacement": "restored_index_mytime345", "include_aliases": true }
GET _cat/indices/
end------------------------------------ Backup and restore a cluster and/or specific indices ---------------------------
PUT /_snapshot/mysnapshot1/my_snapshot3
GET _snapshot/mysnapshot1/my_snapshot2/_status
#下面的例子中由于要求分配副本副本,要确保cluster.routing.allocation.enable参数是否允许(重要) POST /_snapshot/mysnapshot1/my_snapshot3/_mount?wait_for_completion=true { "index": "mytime4", "renamed_index": "mytime1-3-snapshot", "index_settings": { "index.number_of_replicas": 1 }, "ignore_index_settings": [ "index.refresh_interval" ] }
GET /mytime1-3-snapshot/_searchable_snapshots/stats GET /_searchable_snapshots/stats
POST mytime1-3-snapshot/_search { "query": {"match_all": {}} }
POST mytime4/_search { "query": {"match_all": {}} }
POST /_snapshot/mysnapshot1/my_snapshot2/_mount?wait_for_completion=true { "index": ".ds-mytime345-2024.03.04-000001", "renamed_index": "mytime345-data-stream-snapshot", "index_settings": { "index.number_of_replicas": 1 }, "ignore_index_settings": [ "index.refresh_interval" ] }
POST mytime345-data-stream-snapshot/_search { "query": {"match_all": {}} }
PUT _cluster/settings { "persistent": { "cluster.routing.allocation.enable": "all" } }
GET .ds-mytime-2024.03.04-000001/_mapping
GET .ds-mytime--*/_ilm/explain
GET _ilm/policy/my-ilm
GET mytime34/_ilm/explain
HEAD _alias/my_alias_abc
GET _alias/my*
GET my_alias_abc1
POST mytime4/_doc/ { "text": "dfddd thed request", "@timestamp": "1591890612000" }
PUT _index_template/my-ilm-template5 { "priority": 2, "template": { "settings": { "index": { "number_of_shards": "1", "lifecycle.name": "my-ilm" } }, "mappings": { "properties": { "TestTest": { "type": "text" } } }, "aliases": { "my_alias_abc1": { "filter": { "term": { "text": "abc" } } }, "my_alias_abc": {} } }, "index_patterns": [ "mytime345" ], "data_stream": { "hidden": false, "allow_custom_routing": false } }
PUT _ilm/policy/my-ilm {"policy":{"phases":{"hot":{"min_age":"0ms","actions":{"set_priority":{"priority":100},"rollover":{"max_age":"30d","max_primary_shard_size":"50gb"}}},"warm":{"min_age":"30d","actions":{"set_priority":{"priority":50}}},"cold":{"min_age":"50d","actions":{"set_priority":{"priority":0}}}}}}