1.match_all :搜索所有数据
例子:get company/emp/_search
{
"query":{
"match_all": {}
}
}
2.match :匹配
get company/emp/_search
{
"query":{
"match": {
"sex":"m"
}
}
}
3.bool 条件组合
must:必须满足
shoud :可满足可以不满足,通常里面有多个条件,没满足一个就可以
must not:一定不能满足
例子
:get company/emp/_search
{
"query":{
"bool":{
"must":{"match":{"name":"tom"}},
"should": [
{"match":{"name":"E"}},
{"must_not":{....}}
]
, "must_not": [
{....}
],
"minimum_should_match": 1
}
}
}
4.filter
过滤条件,只是过滤数据,不计算相关度分数,而query又相关度计算,一般情况下,如果要以相关度进行排序,那么要用query
性能上对比:filter更加,因为不需要计算相关度,不需要排序,而且内置cache
get company/emp/_search
{
"query":{
"bool":{
"must":[
{
"match":{
"join_date": "2016-01-10"
}
}],
"filter": {
"range": {
"a'ge": {
"gte": 10,
"lte": 20
}
}
}
}
}
}
5.multi match
两个字段中,要求name和friend包含test字段
get company/emp/_search
{
"query":{
"multi_match": {
"query": "test",
"fields": ["name","friend"]
}
}
}
6.range 范围查询
年龄这个字段大于10小于20
get company/emp/_search
{
"query":{
"range": {
"age": {
"gte": 10,
"lte": 20
}
}
}
7.term 包含,不会分词
city中必须包含china
get company/emp/_search
{
"query":{
"term": {
"city": {
"value": "china"
}
}
8.terms
}
}
9.constant_score
排除分数的影响,返回的值score都是1
10._validate 判断搜索语句是否合法
get company/emp/_validate/query?explain
{
"query":{
"match":{
"name":"test"
}
}
}