1、query string search

GET /index/type/_search?q=name:zhangsan&sort=age:desc

2、query DSL(Domain Sepcified Language)

1)查询所有结果

  1. GET /index/type/_search
  2. {
  3. "query":{"match_all":{}}
  4. }

2)根据条件查询

  1. GET /index/type/_search
  2. {
  3. "query":{
  4. "match":{
  5. "name":"zhangsan"
  6. }
  7. },
  8. "sort":[
  9. {
  10. "age":"desc"
  11. }
  12. ]
  13. }

3)分页查询

  1. GET /index/type/_search
  2. {
  3. "query":{"match_all":{}},
  4. "from":1,
  5. "size":2
  6. }

4)指定查询结果的字段

  1. GET /index/type/_search
  2. {
  3. "query":{"match_all":{}},
  4. "_source":["name","age"]
  5. }

3、query filter
  1. GET /index/type/_search
  2. {
  3. "query":{
  4. "bool":{
  5. "must":{
  6. "match":{
  7. "name":"zhangsan"
  8. }
  9. },
  10. "filter":{
  11. "range":{
  12. "age":{"gt":25}
  13. }
  14. }
  15. }
  16. },
  17. "sort":[
  18. {
  19. "age":"desc"
  20. }
  21. ]
  22. }

4、full-text search
  1. GET /index/type/_search
  2. {
  3. "query":{
  4. "match":{
  5. "name":"zhangsan"
  6. }
  7. }
  8. }

5、phrase search(短语搜索:完全匹配)
  1. GET /index/type/_search
  2. {
  3. "query":{
  4. "match_phrase":{
  5. "name":"zhangsan"
  6. }
  7. }
  8. }

6、highlight search(高亮搜索)
  1. GET /index/type/_search
  2. {
  3. "query":{
  4. "match_phrase":{
  5. "name":"zhangsan"
  6. }
  7. } ,
  8. "highlight":{
  9. "fields":{
  10. "name":{}
  11. }
  12. }