# pip install elasticsearch
from datetime import datetime
from elasticsearch import Elasticsearch es_servers = [{
"host": "10.10.6.225",
"port": ""
}] es = Elasticsearch(es_servers) doc = {
'author': 'kimchy',
'text': 'Elasticsearch: cool. bonsai cool.',
'timestamp': datetime.now(),
}
res = es.index(index="test-index", doc_type='tweet', id=1, body=doc)
print(res) res = es.get(index="test-index", doc_type='tweet', id=1)
print(res['_source']) es.indices.refresh(index="test-index") res = es.search(index="test-index", body={"query": {"match_all": {}}})
print("Got %d Hits:" % res['hits']['total'])
for hit in res['hits']['hits']:
print("%(timestamp)s %(author)s: %(text)s" % hit["_source"])

Python创建ES索引的更多相关文章

  1. 创建es索引{"acknowledged"=>true, "shards_acknowledged"=>false}

    创建es索引{"acknowledged"=>true, "shards_acknowledged"=>false} [2018-05-19T13: ...

  2. 创建es索引-格式化和非格式化

    创建es索引-格式化和非格式化 学习了:https://www.imooc.com/video/15768 索引有结构化和非结构化的区分: 1, 先创建索引,然后POST修改mapping 首先创建索 ...

  3. Java创建ES索引实现

    1.pom.xml文件 <dependency> <groupId>org.springframework.boot</groupId> <artifactI ...

  4. python 创建es mapping

    import requests def get_(): url = "http://127.0.0.1:9200/indextest/_mapping?pretty" ss = r ...

  5. Python创建list和按照索引访问list

    Python创建list Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的元素.比如,列出班里所有同学的名字,就可以用一个list表示:>> ...

  6. ES 记录之如何创建一个索引映射,以及一些设置

    ElasticSearch 系列文章 1 ES 入门之一 安装ElasticSearcha 2 ES 记录之如何创建一个索引映射 3 ElasticSearch 学习记录之Text keyword 两 ...

  7. es创建普通索引以及各种查询

    创建索引 创建普通索引: PUT /my_index { "settings": { "index": { "number_of_shards&quo ...

  8. es索引管理工具-curator

    elasticsearch-curator  是官方收购的开源社区周边产品,用来管理es的索引和快照. 官方文档:https://www.elastic.co/guide/en/elasticsear ...

  9. python 操作es

    Elasticsearch 是一个开源的搜索引擎,建立在一个全文搜索引擎库 Apache Lucene™ 基础之上. Lucene 可能是目前存在的,不论开源还是私有的,拥有最先进,高性能和全功能搜索 ...

随机推荐

  1. Memcache PHP 使用笔记

    Memcache PHP 使用笔记 最近在做网站迁移 看到之前的一个网站目录下Cache文件里上万的缓存文件真是害怕 新的服务器上配置了memcache扩展 于是乎准备折腾一下看看能不能把之前的文件缓 ...

  2. mysql 设置默认编码为 utf8

    vi /etc/mysql/mysql.conf.d/mysqld.cnf [client] default-character-set=utf8 [mysql] default-character- ...

  3. go语言从零学起(二)--list循环删除元素(转载)

    本篇系转载 在使用go的container/list的package时,你可能会无意间踩一个小坑,那就是list的循环删除元素. list删除元素,直观写下来的代码如下: package main i ...

  4. TCP、UDP绑定同一端口通信的解释

    昨日突然讨论起TCP与UDP是否可以在同一端口进行绑定,通信. 在印象当中我记得是可以的,今日google了相关资料, 确定以及肯定的: TCP.UDP可以绑定同一端口来进行通信: 网络中可以被命名和 ...

  5. 互斥锁 pthread_mutex_init()函数

    Linux下为了多线程同步,通常用到锁的概念.posix下抽象了一个锁类型的结构:ptread_mutex_t.通过对该结构的操作,来判断资源是否可以访问.顾名思义,加锁(lock)后,别人就无法打开 ...

  6. dp px 互转工具类

    public class DensityUtils { public static int dpToPx(Context context,int dp){ float density = contex ...

  7. WPF控件收集

    1.Extended WPF Toolkit 2.Fluent Ribbon Control Suite 3.WPF Ribbon Control 4.Telerik RadControls for ...

  8. iOS设备分辨率

    CHENYILONG Blog iOS设备分辨率 © chenyilong. Powered by Postach.io Blog

  9. [洛谷P1228]地毯填补问题 题解(分治)

    Description 相传在一个古老的阿拉伯国家里,有一座宫殿.宫殿里有个四四方方的格子迷宫,国王选择驸马的方法非常特殊,也非常简单:公主就站在其中一个方格子上,只要谁能用地毯将除公主站立的地方外的 ...

  10. 【leetcode 简单】 第一百零八题 找到所有数组中消失的数字

    给定一个范围在  1 ≤ a[i] ≤ n ( n = 数组大小 ) 的 整型数组,数组中的元素一些出现了两次,另一些只出现一次. 找到所有在 [1, n] 范围之间没有出现在数组中的数字. 您能在不 ...