当前位置:   article > 正文

Elastisearch 学习_elastalert2 与elastalert 区别联系

elastalert2 与elastalert 区别联系

中文官网网站:

https://www.elastic.co/guide/cn/elasticsearch/guide/current/_retrieving_a_document.html

(基于2.X版本) 7.X版本以后,不再需要类型字段插叙 了

集群健康查询:

curl -XGET 'http://IP:9200/_cluster/health?pretty'

全量查询:

curl -H "Content-Type: application/json" 'http://IP:9200/_count' -d '{"query":{"match_all":{}}}'

关键字查询:

  1. curl -H "Content-Type: application/json" 'http://IP:9200/index_name/type1/_search' -d '{
  2.      "query": {
  3.           "bool": {
  4.                "must": [
  5.                     {
  6.                          "match": {
  7.                               "dutyName": {
  8.                                    "query": "任务名称5169"
  9.                               }
  10.                          }
  11.                     }
  12.                ]
  13.           }
  14.      },
  15.      "from": 0,
  16.      "size": 1
  17. }'

指定文档ID搜索:

curl -H "Content-Type: application/json" 'http://ip:9200/test2/type1/YGKWinoB-a2t_Il3fi3i?pretty'

使用表达式查询

  1. curl -H "Content-Type: application/json" 'http://ip:9200/test2/type1/_search' -d '{
  2. "query":{
  3. "match":{
  4. "dutyId":982
  5. }
  6. }
  7. }'

条件查询

  1. curl -H "Content-Type: application/json" 'http://ip:9200/_search?pretty' -d '{
  2. "query" : {
  3. "bool": {
  4. "must": {
  5. "match" : {
  6. "dutyName" : "任务名称5169"
  7. }
  8. },
  9. "filter": {
  10. "range" : {
  11. "talkTime" : { "gt" : 96}
  12. }
  13. }
  14. }
  15. }
  16. }'

精确匹配 短语搜索:

  1. {
  2. "query" : {
  3. "match_phrase" : {
  4. "about" : "rock climbing"
  5. }
  6. }
  7. }

高亮匹配:在每个搜索结果中 高亮 部分文本片段,以便让用户知道为何该文档符合查询条件

  1. curl -H "Content-Type: application/json" 'http://ip:9200/_search?pretty' -d '{
  2. "query" : {
  3. "bool": {
  4. "must": {
  5. "match" : {
  6. "dutyName" : "任务名称5169"
  7. }
  8. },
  9. "filter": {
  10. "range" : {
  11. "talkTime" : { "gt" : 96}
  12. }
  13. }
  14. }
  15. },
  16. "highlight": {
  17. "fields" : {
  18. "dutyName" : {}
  19. }
  20. }
  21. }'

当执行该查询时,返回结果与之前一样,与此同时结果中还多了一个叫做 highlight 的部分。这个部分包含了 about 属性匹配的文本片段,并以 HTML 标签 <em></em> 封装。

  1. {
  2. "_index" : "agg_duty_test3",
  3. "_type" : "type1",
  4. "_id" : "sEdjmHoBlchvgIdDKWe2",
  5. "_score" : 0.024813946,
  6. "_source" : {
  7. "id" : 19022,
  8. "dutyId" : 22,
  9. "dutyName" : "任务名称8779",
  10. "flowId" : "0c27Oi94JxzKxYb0id8z",
  11. ...
  12. "area" : "0c27Oi94Jx",
  13. "businessType" : "0c27Oi94JxzKxYb0id8zpQ1ZINXnMR",
  14. "phoneNum" : "17847507165"
  15. },
  16. "highlight" : {
  17. "dutyName" : [
  18. "<em>任</em><em>务</em><em>名</em><em>称</em>8779"
  19. ]
  20. }
  21. }

根据日期格式删除es数据:

  1. # ES 7.X以后废弃了 type
  2. curl -H "Content-Type: application/json" 'http://172.31.63.15:9200/index_name/_delete_by_query' -d '{
  3.      "query":{
  4.         "range":{
  5.            "payDate":{
  6.             "lt": "2021-06-26",
  7.             "format":"yyyy-MM-dd"
  8.            }
  9.         }
  10.      }
  11. }'

根据日期条件查询数据

  1. curl -H "Content-Type: application/json" 'http://172.31.63.15:9200/index_name/_search' -d '{
  2.      "query":{
  3.         "range":{
  4.            "payDate":{
  5.             "lt": "2021-06-26",
  6.             "format":"yyyy-MM-dd"
  7.            }
  8.         }
  9.      }
  10. }'


 

待补充整理。。。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/579005
推荐阅读
相关标签
  

闽ICP备14008679号