{"id":18412122,"url":"https://github.com/elliotxx/es-handle","last_synced_at":"2025-04-07T11:31:50.871Z","repository":{"id":86319205,"uuid":"98283888","full_name":"elliotxx/es-handle","owner":"elliotxx","description":"A simple CRUD of ElasticSearch python client","archived":false,"fork":false,"pushed_at":"2019-11-11T08:03:32.000Z","size":3218,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-22T17:03:11.076Z","etag":null,"topics":["elasticsearch","elasticsearch-client","elasticsearch-python","python","python-client"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elliotxx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-25T08:35:27.000Z","updated_at":"2021-12-01T06:42:03.000Z","dependencies_parsed_at":"2023-07-07T06:45:18.792Z","dependency_job_id":null,"html_url":"https://github.com/elliotxx/es-handle","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotxx%2Fes-handle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotxx%2Fes-handle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotxx%2Fes-handle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotxx%2Fes-handle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elliotxx","download_url":"https://codeload.github.com/elliotxx/es-handle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247644250,"owners_count":20972250,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elasticsearch","elasticsearch-client","elasticsearch-python","python","python-client"],"created_at":"2024-11-06T03:39:51.548Z","updated_at":"2025-04-07T11:31:50.864Z","avatar_url":"https://github.com/elliotxx.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"### es-handle - 使用 python client 对 ElasticSearch 进行常用的增删改查操作\n\n#### 声明\n* 运行环境：python 2.7\n* 依赖：elasticsearch ，安装依赖：**pip install elasticsearch**\n* windows 和 linux 环境均已通过测试 \n* 如果有问题，请及时反馈给我\n\n#### 完成清单\n* 增删改查操作：√ \n* -h 帮助信息：√\n* 优化精简 printx 代码：×\n\n\n#### 增删改查支持的参数组合\n命令格式：\n```\nes.py [-h] IP[:port] [-h|option] [-h|index] [type] [id]\n```\n\n| | 增（insert） | 删（delete） | 改（update） | 查（search） | 看（cat） |\n| -------- | -------- | -------- | -------- | -------- | -------- |\n| index,type,id | √     | √     | √     | √     | ×     |\n| index,type    | √     | √     | ×     | √     | ×     |\n| index         | √     | √     | ×     | √     | ×     |\n| null          | ×     | ×     | ×     | √     | √     |\n\n    \n#### 各参数组合使用的 ElasticSearch Python Client API\n\n| | 增（insert） | 删（delete）       | 改（update） | 查（search） | 看（cat）\n| -------- | -------- | -------------| -------- | -------- | -------- |\n| index,type,id | es.index()         | es.delete()          | es.update() | es.get()    | ×                |\n| index,type    | es.index()         | es.delete_by_query() | ×           | es.search() | ×                |\n| index         | es.indices.create()| es.indices.delete()  | ×           | es.search() | ×                |\n| null          | ×                  | ×                    | ×           | es.search() | es.cat.indices() |\n\n#### 安装\n1. 安装 python 2.7\n2. 安装依赖  \n```pip install elasticsearch```\n3. 克隆项目\n4. 进入项目目录，运行程序，查看帮助  \n```es.py -h```\n\n#### Usage\n```\n命令格式：\nes.py [-h] IP[:port] [-h|option] [-h|index] [type] [id]\n\noption:\ninsert - 向 ElasticSearch 插入数据\n    支持 插入指定id的文档、插入不指定id的文档、仅创建 index 三种格式\ndelete - 从 ElasticSearch 删除数据\n    支持 删除文档、删除整个类型(type)、删除整个索引(index) 三种格式\n    注意：如果类型中数据过多，删除操作会异步进行\nupdate - 更新指定 ElasticSearch 文档内容\n    支持 更新指定id的文档内容 一种格式\n    注意：更新的内容应包含在 \"doc\" 关键字中，例：\n    es.py localhost update test_index test_type 1\n    {\n       \"doc\":{\n           \"content\" : \"hello world\"\n       }\n    }\n    如此，索引 test_index 的类型 test_type 中 id 为 1 的文档的\n    content 字段内容更新为\"hello world\"\nsearch - 查询 ElasticSearch 指定内容\n    支持 查询指定id的文档内容、查询指定type、查询指定index、\n    查询所有index 四种格式\ncat    - 查看 ElasticSearch 指定状态\n    默认查看当前所有索引\n\n例子：\n# 查看 ElasticSearch 连接状态\nes.py localhost\n\n# 增(insert)\n# 1. 插入指定 id 的文档\nes.py localhost:9200 insert test_index test_type 1\n{\n    \"title\" : \"Good morning\",\n    \"content\" : \"hello\"\n}\n# 2. 插入不指定 id 的文档\nes.py localhost insert test_index test_type\n输入同上...\n# 3. 创建 index\nes.py localhost insert test_index_2\n{\n    \"settings\" : {\n        \"number_of_shards\" : 1\n    },\n    \"mappings\" : {\n        \"test_type_2\" : {\n            \"properties\" : {\n                \"title\" : { \"type\" : \"text\" },\n                \"content\" : { \"type\" : \"text\" }\n            }\n        }\n    }\n}\n\n# 删(delete)\n# 1. 删除指定 id 的文档\nes.py localhost delete test_index test_type 1\n# 2. 删除整个类型(type)\nes.py localhost delete test_index test_type\n# 3. 删除整个索引(index)\nes.py localhost delete test_index\n\n# 改(update)\n# 1. 更新指定id的文档内容(更新的内容应包含在 \"doc\" 关键字中)\nes.py localhost update test_index test_type 1\n{\n    \"doc\": {\n        \"content\" : \"hello world\"\n    }\n}\n\n# 查(search)\n# 1. 查询指定id的文档内容\nes.py localhost search test_index test_type 1\n# 2. 查询指定type\nes.py localhost search test_index test_type\n# 3. 查询指定index\nes.py localhost search test_index\n# 4. 查询所有index\nes.py localhost search\n\n# 看(cat)\n# 1. 查看 ElasticSearch 所有索引\nes.py localhost cat\n```\n\n#### 参考资料\nElasticSearch Python Client API（官方文档）  \nhttp://elasticsearch-py.readthedocs.io/en/master/api.html\n\npython操作Elasticsearch (一、例子)  \nhttp://www.cnblogs.com/yxpblog/p/5141738.html\n\nelasticsearch的python增删查改实例分析  \nhttp://www.cnblogs.com/skying555/p/6297814.html\n\nHow to update a document using elasticsearch-py?（es.update() 中 body 的格式）  \nhttps://stackoverflow.com/questions/30598152/how-to-update-a-document-using-elasticsearch-py\n\npython中json.dumps使用的坑以及字符编码（json.dumps() 保持真实字符，方便 encode）  \nhttp://www.cnblogs.com/stubborn412/p/3818423.html\n\n怎么知道Python Shell的编码是什么（获得当前shell的编码）  \nhttps://zhidao.baidu.com/question/620013490340115212.html\n\nElasticsearch5.4 删除type（ElasticSearch 删除整个 type）  \nhttp://blog.csdn.net/leafage_m/article/details/74011357\n\nHow to prettyprint a JSON file?（json.dumps() 以便于观看的方式转换 - prettyprint）  \nhttps://stackoverflow.com/questions/12943819/how-to-prettyprint-a-json-file\n\npython类型比较的3种方式（正确比较 if type(s) == 'str'）  \nhttp://blog.csdn.net/five3/article/details/8098556\n\n[解决办法]Python中使用json.loads解码字符串时出错：ValueError: Expecting property name: line 1 column 2 (char 1)（json.loads不能处理单引号的解决办法）  \nhttp://blog.csdn.net/sinsa110/article/details/51189456\n\npython dict按照value 排序（对 dict 进行排序）  \nhttp://blog.csdn.net/buster2014/article/details/50939892\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felliotxx%2Fes-handle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felliotxx%2Fes-handle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felliotxx%2Fes-handle/lists"}