1.query string
a).GET /index/type/_search ===>>查询所有
b).GET /index/type/_search?q=filed:value&sort=filed:desc ===>> 以某个属性的值查询,并排序
2. query dsl(Domain Specified Language 特定领域的语言)
a).查询所有
GET /index/type/_search
{
"query" : {
"match_all" : {}
}
}
b). 查询包含的值,同时排序
GET /index/type/_search
{
"query":{
"match"{
"filed"":"value"
}
},
"sort":[
{"filed": "desc"}
]
}
c).分页查询: from:从第几条开始,size:查询几条
GET /index/type/_search
{
"query" :{
"match_all":{}
} ,
"from":1,
"size":1
}
3.filter查询
GET /index/type/_search
{
"query": {
"bool": {
"must": {
"match": {
"filed": "value"
}
},
"filter": {
"range": {
"filed": {
"gt": "value"
}
}
}
}
}
}
4. 全文检索 (full-text search)
GET /index/type/_search
{
"query" : {
"match" : {
"filed" : "value"
}
}
}
5. 短语搜索(phrase search)
GET /index/type/_search
{
"query": {
"match_phrase": {
"filed": "value"
}
}
}
*注: 短语搜索与全文检索的区别: 全文检索的时候,会先将字段以空格拆分,如 aa bb,统计每个拆分的词在各个文档(document)中出现的次数,而后以查询的值匹配拆分的词的相关度,随后进行返回. 短语搜索则不会进行相关度匹配,必须完全符合才能匹配
6. 高亮搜索(highlight search)
GET /index/type/_search
{
"query": {
"match": {
"filed": "value"
}
},
"highlight": {
"fields": {
"filed": { }
}
}
}
*:在kabana查询时:如果不小心将 GET 误写成 get 返回结果会产生差异,并且不执行query body中的内容,具体问题有待解决