DSL(Domain Specific Language特定領域語言)
Relational DB -> Databases -> Tables -> Rows -> Columns
Elasticsearch -> Indices -> Types -> Documents -> Fields
#####################################################################################################
{
"query": {
"bool": {
"must": [
{"match": {"a": {"query": "1", "type": "phrase"}}},
{"match_not": {"x": {"query": "三", "type": "phrase"}}},
{"range": {"create_time": {"from": "2015-01-01T00:00:00+0800", "to": "2016-01-01T00:00:00+0800"}}},
{"range": {"process_id": {"gt": "1"}}}
],
"should": {
"wildcard": { fileldname: "*"+keyword+"?" }
}
}
},
"from": 100,
"size": 10,
"sort": [{"id": "desc"},{"name": "asc"}]
}
***aggregations, GROUP BY HAVING**********************************
POST cars/_search
{
"size": 0,
"query": {"match_all" : {}},
"aggs": {
"groupBy": {
"terms": {
"field": "keyword",
"size": 20
},
"aggs": {
"count_type": {
"value_count": {"field": "type"}
},
"having": {
"bucket_selector": {
"bucket_path": {"pathAlias": "count_type"},
"script": "params.pathAlias>1"
}
},
"orderBy": {
"bucket_sort": {
"sort": {"value_count": "desc"},
"size": 8
}
}
}
}
}
}
***aggregations*******************************
SELECT count(age) as age_count, avg(age) age, sum(age) sum, max(age) as max from dual ;
"aggs": {
"avg_age": {"avg": {"field": "age"}},
"max_age": {"max": {"field": "age", "missing": "10"}},
"min_age": {"min": {"field": "age", "missing": "10"}},
"sum_age": {"sum": {"field": "age", "script": {"source": "_value * _value"}}},
"count_age": {"value_count": {"field": "age"}}
}
***insert*******************************
POST /index/type/
{ "id": "123", "name": "name123" }
***delete*******************************
POST /index/type/_delete_by_query
{"query": {"match_all": {}}}
***update*******************************
POST /index/type/_update_by_query
{"query": {"match_all": {}},
"script": {
"lang": "painless",
"source": "ctx._source.name=params.name; ctx._source.id=id;",
"params": {"name": "name234", "id": "234"}
}
}