您的位置:首页 > 产品设计 > UI/UE

[elasticsearch笔记] Query DSL [持续更新中]

2019-07-23 17:28 791 查看

note

demo

GET /_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "Search"
}
},
{
"match": {
"content": "Elasticsearch"
}
}
],
"filter": [
{
"term": {
"status": "published"
}
},
{
"range": {
"publish_date": {
"gte": "2015-01-01"
}
}
}
]
}
}
}

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
}
}
}

GET _search
{
"query": {
"bool": {
"filter": {
"term": {
"status": "active"
}
}
}
}
}

GET _search
{
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"term": {
"status": "active"
}
}
}
}
}

GET _search
{
"query": {
"constant_score": {
"filter": {
"term": {
"status": "active"
}
},
"boost": 1.2
}
}
}

GET /_search
{
"query": {
"boosting": {
"positive": {
"term": {
"text": "apple"
}
},
"negative": {
"term": {
"text": "pie tart fruit crumble tree"
}
},
"negative_boost": 0.5
}
}
}

#
# 返回匹配至少一个 query 的搜索,多个匹配时,使用最高的score
#
GET /_search
{
"query": {
"dis_max": {
"queries": [
{
"term": {
"title": "Quick pets"
}
},
{
"term": {
"body": "Quick pets"
}
}
],
"tie_breaker": 0.7
}
}
}

GET /_search
{
"query": {
"function_score": {
"query": {
"match_all": {}
},
"boost": "5",
"random_score": {},
"boost_mode": "multiply"
}
}
}

GET /_search
{
"query": {
"function_score": {
"query": {
"match_all": {}
},
"boost": "5",
"functions": [
{
"filter": {
"match": {
"test": "bar"
}
},
"random_score": {},
"weight": 23
},
{
"filter": {
"match": {
"test": "cat"
}
},
"weight": 42
}
],
"max_boost": 42,
"score_mode": "max",
"boost_mode": "multiply",
"min_score": 42
}
}
}

GET /_search
{
"query": {
"function_score": {
"query": {
"match": {
"message": "elasticsearch"
}
},
"script_score": {
"script": {
"source": "Math.log(2 + doc['likes'].value)"
}
}
}
}
}

GET /_search
{
"query": {
"function_score": {
"query": {
"match": {
"message": "elasticsearch"
}
},
"script_score": {
"script": {
"params": {
"a": 5,
"b": 1.2
},
"source": "params.a / Math.pow(params.b, doc['likes'].value)"
}
}
}
}
}

GET /_search
{
"query": {
"function_score": {
"random_score": {
"seed": 10,
"field": "_seq_no"
}
}
}
}

GET /_search
{
"query": {
"function_score": {
"field_value_factor": {
"field": "likes",
"factor": 1.2,
"modifier": "sqrt",
"missing": 1
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: