Query:處理的是此文檔與之的匹配程度,會計算_score(相關度分數)
Filter:僅僅計算是否匹配,回答的是“是”或者“否”,不計算分數。頻繁使用的filter將被自動緩存
例:
GET /_search
{
"query": {
"bool": {
"must": [
{ "match": { "title": "Search" }},
{ "match": { "content": "Elasticsearch" }}
],
"filter": [
{ "term": { "status": "published" }},
{ "range": { "publish_date": { "gte": "2015-01-01" }}}
]
}
}
}
Bool Query中,
must:匹配文檔中必須出現該分句,并且會對分數產生影響
filter:匹配文檔中必須出現該分句,但是不對分數產生影響
should:匹配一個或者多的should分句
must_not:匹配文檔中必須不能出現該分句
例子:
POST _search
{
"query": {
"bool" : {
"must" : {
"term" : { "user" : "kimchy" }
},
"filter": {
"term" : { "tag" : "tech" }
},
"must_not" : {
"range" : {
"age" : { "gte" : 10, "lte" : 20 }
}
},
"should" : [
{ "term" : { "tag" : "wow" } },
{ "term" : { "tag" : "elasticsearch" } }
],
"minimum_should_match" : 1,
"boost" : 1.0
}
}
}
其中boost是字句權重
Aggregations:
固定形式:
"aggregations" : {
"<aggregation_name>" : {
"<aggregation_type>" : {
<aggregation_body>
}
[,"meta" : { [<meta_data_body>] } ]?
[,"aggregations" : { [<sub_aggregation>]+ } ]?
}
[,"<aggregation_name_2>" : { ... } ]*
}
例如計算平均值:
{
"aggs" : {
"avg_grade" : { "avg" : { "field" : "grade" } }
}
}
一個腳本化的例子:
"aggs" : {
...
"aggs" : {
"avg_corrected_grade" : {
"avg" : {
"field" : "grade",
"script" : {
"lang": "painless",
"inline": "_value * params.correction",
"params" : {
"correction" : 1.2
}
}
}
}
}
}
}
處理缺失值:
{
"aggs" : {
"grade_avg" : {
"avg" : {
"field" : "grade",
"missing": 10
}
}
}
}
去重查詢:
{
"aggs" : {
"author_count" : {
"cardinality" : {
"field" : "author"
}
}
}
}
關于_all字段:
PUT my_index
{
"mappings": {
"type_1": {
"properties": {...}
},
"type_2": {
"_all": {
"enabled": false
},
"properties": {...}
}
}
}
該字段在type_1中是有效的,2中則完全無效
Kibana部分開始...
添加完以后,可以在這里進行一些簡易的搜索
畫一個入門圖...好好玩...
現在我們給這個餅圖加上一個維度——年齡:
一個入門的柱狀圖,用的莎士比亞的表,配置見圖:
注:因為在一開始我們將play_name定義為“keyword”,所以他只能被整個匹配
如果想讓Y軸不從0開始,從最小值開始,可以去Options里選擇“Scale Y-Axis to data bounds”