基本查询
  1. GET wf225/_search
  2. {
  3. "query": {
  4. "match_all": {}
  5. },
  6. "size": 2,//指定条数
  7. "sort": [ //排序
  8. {
  9. "CODE": {
  10. "order": "desc"
  11. }
  12. }
  13. ],
  14. "_source": ["CREATORID","CODE"]//展示指定字段
  15. }

使用keyword查询
  1. GET wf225/_search
  2. {
  3. "query": {
  4. "term": {
  5. "NAME": {
  6. "value": "test"
  7. }
  8. }
  9. }
  10. }
  11. GET wf225/_search
  12. {
  13. "query": {
  14. "terms": {
  15. "NAME": [
  16. "test_child1",
  17. "test_child3"
  18. ]
  19. }
  20. }
  21. }

查询指定范围
  1. GET wf225/_search
  2. {
  3. "query": {
  4. "range": {
  5. "age": {
  6. "gte": 10,
  7. "lte": 20
  8. }
  9. }
  10. }
  11. }

查询指定前缀
  1. GET wf225/_search
  2. {
  3. "query": {
  4. "prefix": {
  5. "NAME": {
  6. "value": "te"
  7. }
  8. }
  9. }
  10. }

通配符查询
  1. GET wf225/_search
  2. {
  3. "query": {
  4. "wildcard": {
  5. "NAME": {
  6. "value": "test*"
  7. }
  8. }
  9. }
  10. }

指定id批量查询
  1. GET wf225/_search
  2. {
  3. "query": {
  4. "ids": {
  5. "values": ["5744866d-df40-4ec5-86f5-d4af0529ec00","5744866d-df40-4ec5-86f5-d4af0529ec99"]
  6. }
  7. }
  8. }

模糊查询
  1. GET wf225/_search
  2. {
  3. "query": {
  4. "fuzzy": {
  5. "NAME": {
  6. "value": "hild"
  7. }
  8. }
  9. }
  10. }

布尔查询

bool 关键字: 用来组合多个条件实现复杂查询 bool表达式查询
must: 相当于&& 同时成立
should: 相当于|| 成立一个就行
must_not: 相当于! 不能满足任何一个

  1. GET wf225/_search
  2. {
  3. "query": {
  4. "bool": {
  5. "must": [
  6. {
  7. "fuzzy": {
  8. "NAME": {
  9. "value": "hild"
  10. }
  11. }
  12. }
  13. ],
  14. "must_not": [
  15. {
  16. "match": {
  17. "NAME": "test_child3"
  18. }
  19. }
  20. ],
  21. "should": [
  22. {
  23. "match": {
  24. "ID": "5744866d-df40-4ec5-86f5-d4af0529ec99"
  25. }
  26. }
  27. ]
  28. }
  29. }
  30. }

高亮显示
  1. GET wf225/_search
  2. {
  3. "query": {
  4. "terms": {
  5. "NAME": [
  6. "test_child1",
  7. "test_child3"
  8. ]
  9. }
  10. },
  11. "highlight": {
  12. "pre_tags": ["<span style='color:red'>"],
  13. "post_tags": ["</span>"],
  14. "require_field_match":true,
  15. "fields": {"*":{}}
  16. }
  17. }

分词后,多字段查询
  1. GET wf225/_search
  2. {
  3. "query": {
  4. "multi_match": {
  5. "query": "test",
  6. "fields": ["NAME","ID"]
  7. }
  8. }
  9. }

指定分词器查询
  1. GET wf225/_search
  2. {
  3. "query": {
  4. "query_string": {
  5. "default_field": "NAME",
  6. "query": "test",
  7. "analyzer": "ik_max_word"
  8. }
  9. }
  10. }