首页 > 其他 > 详细

elasticsearch查询DLS

时间:2020-08-05 18:44:50      阅读:136      评论:0      收藏:0      [点我收藏+]

检查集群健康状况:

GET /_cat/health?v

查看所有索引:

GET /_cat/indices?v

创建索引:

PUT /test_index1
PUT /product
{
  "settings" : {
      "number_of_shards" : 3,
      "number_of_replicas" : 1
   }
}

POST /product/_mapping?pretty 
{
  "_source": {"enabled": true},
  "dynamic": true,
  "properties" : {
    "imei" : {"type" : "text","analyzer" : "keyword","fielddata": true},
    "ispid" : {"type":"integer","ignore_malformed": true},
    "msisdn" : {"type" : "text","analyzer" : "keyword","fielddata": true},
    "maddr_s" : {"type" : "text","analyzer" : "ik_max_word","norms" : false,"fields" : {"raw" : {"type" : "keyword","doc_values":true}}},
    "maddr_p" : {"type" : "text","analyzer" : "ik_max_word","norms" : false,"fields" : {"raw" : {"type" : "keyword","doc_values":true}}},
    "maddr_c" : {"type" : "text","analyzer" : "ik_max_word","norms" : false,"fields" : {"raw" : {"type" : "keyword","doc_values":true}}},
    "netaddr_s" : {"type" : "text","analyzer" : "ik_max_word","norms" : false,"fields" : {"raw" : {"type" : "keyword","doc_values":true}}},
    "netaddr_p" : {"type" : "text","analyzer" : "ik_max_word","norms" : false,"fields" : {"raw" : {"type" : "keyword","doc_values":true}}},
    "netaddr_c" : {"type" : "text","analyzer" : "ik_max_word","norms" : false,"fields" : {"raw" : {"type" : "keyword","doc_values":true}}},
    "seraddr_s" : {"type" : "text","analyzer" : "ik_max_word","norms" : false,"fields" : {"raw" : {"type" : "keyword","doc_values":true}}},
    "seraddr_p" : {"type" : "text","analyzer" : "ik_max_word","norms" : false,"fields" : {"raw" : {"type" : "keyword","doc_values":true}}},
    "seraddr_c" : {"type" : "text","analyzer" : "ik_max_word","norms" : false,"fields" : {"raw" : {"type" : "keyword","doc_values":true}}},
    "uli" : {"type" : "text","analyzer" : "ik_max_word","norms" : false,"fields" : {"raw" : {"type" : "keyword","doc_values":true}}},
    "x_sip" : {"type" : "ip"},
    "x_dip" : {"type" : "ip"},
    "i_sport" : {"type" : "keyword","doc_values":true},
    "i_dport" : {"type" : "keyword","doc_values":true},
    "guti" : {"type" : "keyword","doc_values":true},
    "i_nsapi" : {"type" : "long","ignore_malformed": true},
    "apn" : {"type" : "text", "analyzer" : "keyword"},
    "rai" : {"type" : "text", "analyzer" : "keyword"},
    "gsnu" : {"type" : "text", "analyzer" : "keyword"},
    "teid" : {"type" : "text", "analyzer" : "keyword"},
    "endtime" : {"type" : "long","ignore_malformed": true},
    "id" : {"type" : "long"},
    "i_type" : {"type" : "text","analyzer" : "keyword"},
    "conndirect" : {"type" : "text", "analyzer" : "keyword"},
    "protocoltype" : {"type" : "text" ,"analyzer" : "keyword"},
    "i_trojan_type" : {"type" : "long","ignore_malformed": true},
    "pguti":{"type" : "text" ,"analyzer" : "keyword"},
    "sid":{"type" : "text" ,"analyzer" : "keyword"},
    "x_imsi":{"type" : "text" ,"analyzer" : "keyword","fielddata": true},
    "pteid":{"type" : "text" ,"analyzer" : "keyword"},
    "flow":{"type" : "long","ignore_malformed": true},
    "vpsfirm":{"type" : "text" ,"analyzer" : "keyword"},
    "x_begintime":{"type" : "long","ignore_malformed": true},
    "netaddr" : {"type" : "keyword","doc_values":true},
    "seraddr" : {"type" : "keyword","doc_values":true},
    "maddr" : {"type" : "keyword","doc_values":true},
    "paddr_s" : {"type" : "text","analyzer" : "ik_max_word","norms" : false,"fields" : {"raw" : {"type" : "keyword","doc_values":true}}},
    "paddr_p" : {"type" : "text","analyzer" : "ik_max_word","norms" : false,"fields" : {"raw" : {"type" : "keyword","doc_values":true}}},
    "paddr_c" : {"type" : "text","analyzer" : "ik_max_word","norms" : false,"fields" : {"raw" : {"type" : "keyword","doc_values":true}}},
    "paddr" : {"type" : "keyword","doc_values":true},


    "sshclient" : {"type" : "keyword","doc_values":true},
    "sshserver" : {"type" : "keyword","doc_values":true},
    "sshver" : {"type" : "keyword","doc_values":true},
    "b_firstpacket" : {"type" : "binary"},
    "b_firstpacket1" :  {"type" : "text", "analyzer" : "keyword"},
    "appbigt" :{"type" : "integer"},
    "appsubt" :{"type" : "integer"}
  }
}

查看索引:

GET /posts/_search

删除索引:

DELETE /test_index

插入数据:

POST /student/_bulk
{ "index": { "_id": 1 }}
{ "name" : "liubei", "age" : 20 , "sex": "boy", "birth": "1996-01-02" , "about": "i like diaocan he girl" }
{ "index": { "_id": 2 }}
{ "name" : "guanyu", "age" : 21 , "sex": "boy", "birth": "1995-01-02" , "about": "i like diaocan" }
{ "index": { "_id": 3 }}
{ "name" : "zhangfei", "age" : 18 , "sex": "boy", "birth": "1998-01-02" , "about": "i like travel" }
{ "index": { "_id": 4 }}
{ "name" : "diaocan", "age" : 20 , "sex": "girl", "birth": "1996-01-02" , "about": "i like travel and sport" }
{ "index": { "_id": 5 }}
{ "name" : "panjinlian", "age" : 25 , "sex": "girl", "birth": "1991-01-02" , "about": "i like travel and wusong" }
{ "index": { "_id": 6 }}
{ "name" : "caocao", "age" : 30 , "sex": "boy", "birth": "1988-01-02" , "about": "i like xiaoqiao" }
{ "index": { "_id": 7 }}
{ "name" : "zhaoyun", "age" : 31 , "sex": "boy", "birth": "1997-01-02" , "about": "i like travel and music" }
{ "index": { "_id": 8 }}
{ "name" : "xiaoqiao", "age" : 18 , "sex": "girl", "birth": "1998-01-02" , "about": "i like caocao" }
{ "index": { "_id": 9 }}
{ "name" : "daqiao", "age" : 20 , "sex": "girl", "birth": "1996-01-02" , "about": "i like travel and history" }

match匹配, term精确匹配, range范围过滤, exists包含某个字段.  all_interests自己定义的聚合名称:

GET /student/_search
{
    "query": {
      "bool":{
        "must":[
          {
         "match": {
           "about": "travel"
             }
          },
          {
            "term":{
                "sex":"boy"
            }
            
          },
          {
            "range":{
              "age":{
                "gt":16,
                "lte":25
              }
            }
            
          },
          {
            "exists":{
              "field":"age"
            }
          }
          ]
      }
     },
    "aggs": {
    "all_interests": {
      "terms": { "field": "age" }
    }
  }
}

模糊查询:

GET /student/_search
{"query": {
    "wildcard":{
      "name": "li"
    }
   
  }  
}

聚合查询: all_interests自己定义的聚合名称

GET /student/_search
{
  "aggs": {
    "all_interests": {
      "terms": { "field": "age" }
    }
  }
}

 

elasticsearch查询DLS

原文:https://www.cnblogs.com/chong-zuo3322/p/13441638.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!