es数据库crud 【python】

Scroll Down

删除

es.indices.delete(index='sales_index', ignore=[400, 404])

或条件查询;升序排序,时间范围查询

{
    "query": {
        "bool": {
            "must": [
                {
                    "bool": {
                        "should": [
                            {
                                "term": {
                                    "gid.keyword": "zqc2YHYBTKwdshTxWqn_"
                                }
                            },
                            {
                                "term": {
                                    "gid.keyword": "Zqc2YHYBTKwdshTxWqn_"
                                }
                            }
                        ]
                    }
                },
                {
                    "range": {
                        "start_date": {
                            "gte": "2020-12-14",
                            "lt": "2021-05-03"
                        }
                    }
                }
            ]
        }
    },
    "sort": {
        "year": {
            "order": "asc"
        }
    },
    "size": 100

}

注意,如果需要搜索全部数据:

#获取超过1w条数据 需要加上 "track_total_hits":true ,不然只能显示出9999条
GET /pg03_h3/_doc/_search
{
"_source":["terminalId",
"lon",
"lat",
"time",
"h3_2"
],
"query": {"match": {
"h3_2":"586321722337132543"
}},
"size":10000,
"track_total_hits":true
}