栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

es http请求json封装(没必要这么做,领导要求,记录一下)

es http请求json封装(没必要这么做,领导要求,记录一下)

es服务器地址:http://127.0.0.1:9100/

[Elasticsearch: 权威指南]:(https://www.elastic.co/guide/cn/elasticsearch/guide/current/index.html)https://www.elastic.co/guide/cn/elasticsearch/guide/current/_creating_an_index.html

1. es 查询(GET)

Match会根据该字段的分词器,进行分词查询。

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "collectionAddr": {
              "query": "基本",
              "operator": "OR",
              "prefix_length": 0,
              "max_expansions": 50,
              "fuzzy_transpositions": true,
              "lenient": false,
              "zero_terms_query": "NONE",
              "auto_generate_synonyms_phrase_query": true,
              "boost": 1
            }
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1
    }
  }
}
################################返回#################################
{
    "took": 29,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 2,
        "max_score": 1.5098256,
        "hits": [
            {
                "_index": "new_fencedata",
                "_type": "imsidatavo",
                "_id": "s0gam38BF5S9qAGRcZkC",
                "_score": 1.5098256,
                "_source": {
                    "_class": "com.hame.start.common.es.IMSIDataVo",
                    "id": "",
                    "dataSn": "",
                    "dataImsi": "",
                    "dataImei": "",
                    "operator": 0,
                    "systemtype": 0,
                    "isvirtual": true,
                    "phone": "",
                    "province": "",
                    "city": "",
                    "idMonitorsite": "",
                    "idEquipment": "",
                    "collectionAddr": "基本原则",
                    "placeLongitude": 0.0,
                    "placelatitude": 0.0,
                    "equipgeo": {
                        "lat": 0.0,
                        "lon": 0.0
                    }
                }
            },
            {
                "_index": "new_fencedata",
                "_type": "imsidatavo",
                "_id": "KHeVtX8Brq3IwN_ull-0",
                "_score": 1.113083,
                "_source": {
                    "_class": "com.hame.start.common.es.IMSIDataVo",
                    "id": "",
                    "dataSn": "",
                    "dataImsi": "",
                    "dataImei": "",
                    "operator": 0,
                    "systemtype": 0,
                    "isvirtual": true,
                    "phone": "",
                    "province": "",
                    "city": "",
                    "idMonitorsite": "",
                    "idEquipment": "",
                    "collectionAddr": "基本原则",
                    "placeLongitude": 0.0,
                    "placelatitude": 0.0,
                    "equipgeo": {
                        "lat": 0.0,
                        "lon": 0.0
                    }
                }
            }
        ]
    }
}

2. 分词演示(GET)

127.0.0.1:9200/_analyze

{
  "analyzer": "ik_max_word", #分词器
  "text": "基本原则" #分词中文 
}

3. 带索引查询(GET)

127.0.0.1:9200/new_fencedata/_search

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "collectionAddr": {
              "query": "基本",
              "operator": "OR" # operator操作符 要求and或者or匹配文本的分词
            }
          }
        }
      ]
    }
  }
}

4. 不带索引查询(GET)

127.0.0.1:9200/_search

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "name": {
              "query": "测试",
              "operator": "OR" # operator操作符 要求and或者or匹配文本的分词
            }
          }
        }
      ]
    }
  }
}	

5. 添加索引映射(PUT)

127.0.0.1:9200/indexName

{
  "settings": {
    "number_of_shards": 5 #每个索引的主分片数,默认值是 5 。这个配置在索引创建后不能修改。
  },
"mappings": {#映射
         "doc": { #type 对像名称
            "properties": { #属性
               "date": {
                  "type": "date",
                  "format": "strict_date_optional_time||epoch_millis"
               },
               "name": {
                  "type": "keyword"
               },
               "tweet": {
                  "type": "text",
				  
					"analyzer": "ik_smart",

					"search_analyzer": "ik_smart"
               },
               "user_id": {
                  "type": "long"
               }
            }
         }
      }
}

6. 索引插入数据(POST)

127.0.0.1:9200/aqab/doc/1

127.0.0.1:9200/indexName/type/id

{"name": "测试"}

7. 删除索引下数据(DELETe)

127.0.0.1:9200/aqab/doc/1

8. 删除索引(DELETE)

127.0.0.1:9200/aqab

9. 条件删除(索引+时间范围)

127.0.0.1:9200/new_fencedata/_search

{"query":{
        "range" : {
          "dateTime" : {
            "from" : 1647242553763,
            "to" : 1648106553763,
            "include_lower" : true,
            "include_upper" : true,
            "boost" : 1.0
          }
        }
}}

10. 条件查询(GET)时间范围

127.0.0.1:9200/_search

{"query":{
        "range" : {
          "dateTime" : {
            "from" : 1647242553763,
            "to" : 1648106553763,
            "include_lower" : true,
            "include_upper" : true,
            "boost" : 1.0
          }
        }
}}

11. 条件删除(POST)索引+时间范围

127.0.0.1:9200/aqabaaa/_delete_by_query

{"query":{
        "range" : {
          "dateTime" : {
            "from" : 1647242553763,
            "to" : 1648106553763,
            "include_lower" : true,
            "include_upper" : true,
            "boost" : 1.0
          }
        }
}}

12 . 条件删除(POST)时间范围+所有数据

127.0.0.1:9200/*/_delete_by_query

{"query":{
        "range" : {
          "dateTime" : {
            "from" : 1647242553763,
            "to" : 1648106553763,
            "include_lower" : true,
            "include_upper" : true,
            "boost" : 1.0
          }
        }
}}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/774379.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号