elasticsearch-py

Elasticsearch基本操作

…衆ロ難τιáo~ 提交于 2021-02-16 03:00:59
在学习Elasticsearch的过程中想找一些可以系统的描述es操作的文章,但是官网没有中文页面,ES中文指南的排版和翻译又很突兀和不协调,因此决定自己看一遍官方的maunal总结一下,由于没时间把所有章节全部翻一遍,所以写一篇学习笔记以便完成初步的学习。 概念总览: 在描述ES的基本操作之前,首先来介绍几个概念: Relational DB -> Databases -> Tables -> Rows -> Columns Elasticsearch -> Indices -> Types -> Documents -> Fields 以上是早期的官方文档贴出的一个概念介绍图,其含义不用多说,其实ES更适合与MongoDB类比: MongoDB -> DBs -> Collections -> Documents -> Fields Elasticsearch -> Indices -> Types -> Documents -> Fields ES里的Index可以看做一个库,Documents相当于表的行,而Types相当于表。 但是Types的概念将会被逐渐弱化并可能在未来版本中删除,而在Elasticsearch 6中,一个index下已经只能包含一个type了,因此可以将index理解为一个表,types意如其名仅用于展示一个document所属的分类

【Python】Elasticsearch和elasticsearch_dsl

半腔热情 提交于 2021-02-13 07:27:21
官网: https://elasticsearch-py.readthedocs.io/en/master/api.html 官网: https://github.com/elastic/elasticsearch-py/tree/master/elasticsearch/client 官网: https://elasticsearch-dsl.readthedocs.io/en/latest/api.html from elasticsearch_dsl import connections, Search from elasticsearch import Elasticsearch from elasticsearch.exceptions import * es_object = Elasticsearch([ ' url:9200 ' ], sniffer_timeout=60, timeout=30 ) # 获取es中所有的索引 # 返回类型为字典,只返回索引名 es_object.cat.indices(format= ' json ' ,h= ' index ' ) # 查询多个索引 es_s_object = Search(using = es_object, index = [ ' log-2018-07-31 ' , ' log-2018-07-30 ' ,

Elasticsearch: scroll between specified time frame

回眸只為那壹抹淺笑 提交于 2021-01-29 10:32:18
问题 I have some data in elasticsearch. as shown in the image I used below link example to do the scrolling https://gist.github.com/drorata/146ce50807d16fd4a6aa page = es.search( index = INDEX_NAME, scroll = '1m', size = 1000, body={"query": {"match_all": {}}}) sid = page['_scroll_id'] scroll_size = page['hits']['total'] # Start scrolling print( "Scrolling...") while (scroll_size > 0): print("Page: ",count) page = es.scroll(scroll_id = sid, scroll = '10m') # Update the scroll ID sid = page['

Convert Kibana query (create index pattern) to Python request

丶灬走出姿态 提交于 2020-08-10 03:37:31
问题 I'm trying to convert this Kibana query to Python: PUT /.kibana/_doc/index-pattern:tempindex { "type": "index-pattern", "index-pattern": { "title": "tempindex", "timeFieldName": "sendTime" } } This is what I have so far: HEADERS = { 'Content-Type': 'application/json' } uri = "http://localhost:5601/_doc/index-pattern:tempindex" query = json.dumps({ "type": "index-pattern", "index-pattern": { "title": "tempindex", "timeFieldName": "sendTime" } }) r = requests.put(uri, headers=HEADERS, data

What is the Elasticsearch-py equivalent to alias actions?

好久不见. 提交于 2020-05-25 13:30:59
问题 I am trying to implement multiples indices approach using elasticsearch-dsl. There are basically two steps: 1. Create aliases: PUT /tweets_1/_alias/tweets_search PUT /tweets_1/_alias/tweets_index 2. Change alias when necessary: POST /_aliases { "actions": [ { "add": { "index": "tweets_2", "alias": "tweets_search" }}, { "remove": { "index": "tweets_1", "alias": "tweets_index" }}, { "add": { "index": "tweets_2", "alias": "tweets_index" }} ] } I could only implement the step 1 using

What is the Elasticsearch-py equivalent to alias actions?

人盡茶涼 提交于 2020-05-25 13:27:28
问题 I am trying to implement multiples indices approach using elasticsearch-dsl. There are basically two steps: 1. Create aliases: PUT /tweets_1/_alias/tweets_search PUT /tweets_1/_alias/tweets_index 2. Change alias when necessary: POST /_aliases { "actions": [ { "add": { "index": "tweets_2", "alias": "tweets_search" }}, { "remove": { "index": "tweets_1", "alias": "tweets_index" }}, { "add": { "index": "tweets_2", "alias": "tweets_index" }} ] } I could only implement the step 1 using

Delete nested array in elasticsearch

怎甘沉沦 提交于 2020-04-29 23:39:26
问题 I have documents containing nested tables in the following format : { "dataId": "dataIdentifier", "versionId": "versionIdentifier", "items": [ { "obj1": "value1", "obj2": "value2", "obj3": "value3", }, { "obj1": "value4", "obj2": "value5", "obj3": "value6" }, { "obj1": "value7", "obj2": "value8", "obj3": "value9" } ] } With "items" being of nested type. I want to delete one of the elements inside the "items" given than one of the object inside has a certain value. For instance it would be :

ElasticSearch add authentication to only DELETE index API

牧云@^-^@ 提交于 2020-04-18 06:31:10
问题 I have hosted a shared elasticsearch index (IP Restricted though using GCP Firewall) but I want to add any kind of security on this Index so that others can do any operations freely as they are doing now without any notice but dont want to allow anybody except (having auth) to delete the entire Index. My ElasticSearch details: { "name" : "node-1", "cluster_name" : "production", "cluster_uuid" : "<hash>", "version" : { "number" : "7.1.1", "build_flavor" : "default", "build_type" : "tar",

Replication es.search (index_results.execute()) for es.scroll

99封情书 提交于 2020-02-07 05:35:49
问题 I am using the python dsl library When I do a standard search I use execute(), this is a method that will return a Response object (https://elasticsearch-dsl.readthedocs.io/en/latest/search_dsl.html). Looks to have .search at the heart of it In some cases I to use scroll . This works, but it returns a dictionary. What I want to do is use scroll but to return a response in the same way that execute() does The DSL Elasticsearch function does this def execute(self, ignore_cache=False): """

How to turn a curl into elasticsearch-py query format?

我与影子孤独终老i 提交于 2019-12-25 09:01:50
问题 How to write elasticsearch-py query to query the same data as below? --data-binary '{"query": {"filtered": {"query": {"bool": {"should":[ {"query_string": {"query":"request.action.raw:\"aaa\" AND (loglevel:INFO)"}}, {"query_string": {"query":"request.action.raw:\"bbb\" AND (loglevel:INFO)"}}, {"query_string": {"query":"request.action.raw:\"ccc\" AND (loglevel:INFO)"}}, } }, "filter": {"bool": {"must":[ {"range": {"@timestamp": {"from":111,"to":222}}}, {"fquery": {"query": {"query_string": {