1、创建索引
PUT gsku_city_sale_data_beta_index
{
"settings": {
"index": {
"number_of_shards": "5",
"number_of_replicas": "1"
}
},
"mappings": {
"grsku_city_sale_data_beta_type": {
"dynamic": "false",
"_source": {
"enabled": "true"
},
"properties": {
"sku_id": {
"type": "keyword"
},
"sku_num": {
"type": "integer"
},
"sku_gmv": {
"type": "double"
},
"city_id": {
"type": "integer"
},
"city_name": {
"type": "keyword"
},
"province_id": {
"type": "integer"
},
"province_name": {
"type": "keyword"
},
"dt": {
"type": "keyword"
}
}
}
}
}
2、根据文档id查询
GET address_boundary_index/address_boundary_type/110000
3、查询某个字段为null的记录
GET address_boundary_beta_index/_search
{
"query": {
"bool": {
"must_not": {
"exists": {
"field": "bd_geometry"
}
}
}
},
"from": 0,
"size": 100
}
4、修改某个文档的字段
POST address_boundary_test_index/address_boundary_test_type/220000/_update
{
“doc”: {
“bd_center”: “126.564543989, 43.8719883344”
}
}
删除记录:
DELETE zone_test_index/zone_grid_test_type/文档id
POST zone_test_index/_delete_by_query
{
"query": {
"bool": {
"must": [
{
"term":{
"level": 5
}
}
]
}
}
}
5、地址距离搜索
GET community_info_index/_search
{
"query": {
"bool" : {
"filter" : [
{
"term" : {
"dt" : {
"value" : "2021-08-15",
"boost" : 1.0
}
}
},
{
"geo_distance" : {
"lonlat_bd" : [
112.311694,
34.549972
],
"distance" : 3000.0,
"distance_type" : "arc",
"validation_method" : "STRICT",
"ignore_unmapped" : false,
"boost" : 1.0
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
}
6、去重
7、新增字段
PUT zone_test_index/_mapping/zone_grid_test_type
{
"zone_test_type":{
"properties": {
"b_grid_id": {
"type": "keyword"
}
}
}
}
8、重建索引修改字段
POST _reindex
{
"source": {
"index": "test"
},
"dest": {
"index": "test2"
},
"script": {
"source": "ctx._source.tag = ctx._source.remove(\"flag\")"
}
}
9、脚本修改字段
POST aoi_data_info_test_index/_update_by_query
{
"query": {
"constant_score" : {
"filter" : {
"exists" : { "field" : "aoi_center_bd" }
}
}
},
"script": {
"source": """
if(ctx._source.aoi_center_bd instanceof String){
String s=ctx._source.aoi_center_bd;
String res = new String();
ArrayList arr = new ArrayList();
if(!s.isEmpty()){
String splitter = ",";
StringTokenizer tokenValue = new StringTokenizer(s, splitter);
while (tokenValue.hasMoreTokens()) {
arr.add(tokenValue.nextToken());
}
res = arr[1] + "," + arr[0];
}
ctx._source.bd_center_point=res;
}
"""
}
}
10、同一记录的不同字段等值查询
GET g_info_index/_search
{
"query": {
"bool": {
"must": [
{
"match_all": {}
}
],
"filter": [
{
"script": {
"script": {
"source": "doc['grid_id']==doc['grid_id']"
}
}
}
]
}
},
"from": 0,
"size": 10
}
11、having coucnt(*)查询
GET j_info_index/_search
{
"size": 0,
"aggs": {
"grid_id": {
"terms": {
"field": "grid_id"
},
"aggs": {
"the_filter": {
"bucket_selector": {
"buckets_path": {
"the_doc_count": "_count"
},
"script": "params.the_doc_count > 1"
}
}
}
}
}
}
删除ES中数据
https://kibana-ecn-north-1.com/es/jx_grid_info_index/jx_grid_info_type/2453/
GET jbeta_info_index/_search
{
"query": {
"bool": {
"must": [
{"term": {
"valid_status": {
"value": "1"
}
}}
]
}
},
"size": 0,
"aggs": {
"grid_id": {
"terms": {
"field": "grid_id",
"size": 10000
},
"aggs": {
"the_filter": {
"bucket_selector": {
"buckets_path": {
"the_doc_count": "_count"
},
"script": "params.the_doc_count > 1"
}
}
}
}
}
}
GET jbeta_info_index/_search
{
"query": {
"bool": {
"must": [
{"term": {
"valid_status": {
"value": "1"
}
}}
]
}
},
"size": 0,
"aggs": {
"grid_id": {
"terms": {
"field": "grid_id",
"size": 10000
},
"aggs": {
"the_filter": {
"bucket_selector": {
"buckets_path": {
"the_doc_count": "_count"
},
"script": "params.the_doc_count > 1"
}
}
}
}
}
}
查一个坐标命中那个网格
GET j_info_index/_search
{
"query": {
"bool" : {
"filter" : [
{
"geo_shape" : {
"bd_boundary" : {
"shape" : {
"type" : "circle",
"radius" : "10.0cm",
"coordinates" : [
118.03624603737356,
36.82046585967171
]
},
"relation" : "contains"
},
"ignore_unmapped" : false,
"boost" : 1.0
}
},
{
"term" : {
"valid_status" : {
"value" : 1,
"boost" : 1.0
}
}
},
{
"term" : {
"grid_main_type" : {
"value" : 200,
"boost" : 1.0
}
}
}
],
"adjust_pure_negative" : true,
"boost" : 1.0
}
}
}