查询请求体说明

elasticsearch 使用版本6.0.1

// 组合多查询 使用bool查询来满足你的需求
$query_arr = [
'bool' => [
'must' => [

],
'should' => [

],
'filter' => [

],
// 最少should匹配数
'minimum_should_match' => 1
]
];

must
文档必须匹配这些条件
must_not
文档必须不匹配这些条件
should
如果满足这些语句的任意语句,将增加_score,否则,无任何影响。
可以理解为sql中的or
filter
必须匹配,但他以不评分过滤模式来进行,这些语句对_score没有贡献,只是根据过滤标准来排除或包含文档。
可以理解为查出文档的范围,must和must not是精确搜索
// constant_score查询
尽管没有 bool 查询使用这么频繁,constant_score 查询也是你工具箱里有用的查询工具。
它将一个不变的常量评分应用于所有匹配的文档。它被经常用于你只需要执行一个 filter 而没有其它查询(例如,评分查询)的情况下。
可以使用它来取代只有 filter 语句的 bool 查询。在性能上是完全相同的,但对于提高查询简洁性和清晰度有很大帮助。
{
"constant_score": {
  "filter": {
  "term": { "column": "value" }
    }
}
}

// 排序
$order = ['userid' => ['order' => 'desc']];
// 查询种类
match  标准查询
{ "match": { "tweet": "About Search" }}
{ "match": { "age": 26 }}
{ "match": { "date": "2014-09-01" }}
{ "match": { "public": true }}
{ "match": { "tag": "full_text" }}

multi_match  查询可以在多个字段上执行相同match查询
{
"multi_match": {
"query": "full text search",
"fields": [ "title", "body" ]
}
}
range  查询找出那些落在指定区间内的数字或时间
{
"range": {
"age": {
"gte": 20,
"lt": 30
}
}
}
gt大于
gte大于等于
lt小于
lte小于等于

term  精确值匹配,这些精确值可能是数字、时间、布尔或者那些 not_analyzed 的字符串
{ "term": { "age": 26 }}
{ "term": { "date": "2014-09-01" }}
{ "term": { "public": true }}
{ "term": { "tag": "full_text" }}

terms 和 term 查询一样,但它允许你指定多值进行匹配。如果这个字段包含了指定值中的任何一个值,那么这个文档满足条件
{ "terms": { "tag": [ "search", "full_text", "nosql" ] }}

exists 和 missing  被用于查找那些指定字段中有值 (exists) 或无值 (missing) 的文档。这与SQL中的 IS_NULL (missing) 和 NOT IS_NULL (exists) 在本质上具有共性
{
"exists": {
"field": "title"
}
}

猜你喜欢

转载自www.cnblogs.com/leee99/p/11060001.html