- 查詢所有
GET /_search //所有索引惠毁,所有type下的所有數(shù)據(jù)都搜索出來(lái)
{
"query": {
"match_all": {}
}
}
GET /test_index/_search //指定一個(gè)index尖奔,搜索其下所有type的數(shù)據(jù)
{
"query": {
"match_all": {}
}
}
GET /test_index,test_index2/_search //同時(shí)搜索兩個(gè)index下的數(shù)據(jù)
{
"query": {
"match_all": {}
}
}
GET /*1,*2/_search //按照通配符去匹配多個(gè)索引
{
"query": {
"match_all": {}
}
}
GET /test_index/test_type/_search //搜索一個(gè)index下指定的type的數(shù)據(jù)
{
"query": {
"match_all": {}
}
}
GET /test_index/test_type,test_type2/_search //可以搜索一個(gè)index下多個(gè)type的數(shù)據(jù)
{
"query": {
"match_all": {}
}
}
GET /test_index,test_index2/test_type,test_type2/_search //搜索多個(gè)index下的多個(gè)type的數(shù)據(jù)
{
"query": {
"match_all": {}
}
}
GET /_all/test_type,test_type2/_search //可以代表搜索所有index下的指定type的數(shù)據(jù)
{
"query": {
"match_all": {}
}
}
- match
GET /_search
{
"query": {
"match": {
"title": "elasticsearch"
}
}
}
- multi match
GET /_search
{
"query": {
"multi_match": {
"query": "elasticsearch",
"fields": ["title","content"]
}
}
}
- range query
GET /company/employee/_search
{
"query": {
"range": {
"age": {
"gte": 30
}
}
}
}
- term query
//term 查詢被用于精確值 匹配钳垮,這些精確值可能是數(shù)字马昨、時(shí)間把曼、布爾或者那些 not_analyzed 的字符串
//term 查詢對(duì)于輸入的文本不 分析 胡岔,所以它將給定的值進(jìn)行精確查詢
GET /_search
{
"query": {
"term": {
"title":"test hello"
}
}
}
- terms query
//terms 查詢和 term 查詢一樣椿息,但它允許你指定多值進(jìn)行匹配歹袁。
//如果這個(gè)字段包含了指定值中的任何一個(gè)值坷衍,那么這個(gè)文檔滿足條件:
{ "terms": { "tag": [ "search", "full_text", "nosql" ] }}
定制排序
查詢的默認(rèn)情況是按照_score排序的,然而某些情況下条舔,可能沒有有用的_score枫耳,比如說(shuō)filter或constant_score
GET _search
{
"query": {
"bool": {
"filter": {
"term": {
"author_id": 110
}
}
}
}
}
GET _search
{
"query": {
"constant_score": {
"filter": {
"term": {
"author_id": 110
}
}
}
}
}
定制排序規(guī)則
GET /company/employee/_search
{
"query": {
"constant_score": {
"filter": {
"range":{
"age":{
"gte":30
}
}
}
}
},
"sort": [
{
"join_date": {
"order": "asc"
}
}
]
}