• 技术文章 >Python技术 >Python高级

    python中elasticsearch是什么?

    十一十一2021-03-05 09:51:08原创4134

    本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

    安装库:

    pip install elasticsearch

    引入库:

    from elasticsearch import ElasticSearch
    es = ElasticSearch(['localhost:9200'])

    创建索引:

    es.indices.create(index='project', ignore=400)

    删除索引:

    es.indices.delete(index='project', ignore_unavailable=True)

    插入数据:

    for i in range(10):
        body = {
            'name': '张三' % i,
            'age': 20 + i,
            'desc': '我是张家的老' % i
        }
        es.create(index='project', doc_type='_doc', body=body, id=i)

    elasticsearch是非常适合存索引的,在处理数据上也有些许适应,大家感兴趣的话,可以按照上述提供的内容,详细做了解学习。

    专题推荐:elasticsearch是什么
    品易云
    上一篇:python中ansible是什么? 下一篇:python中Insert函数怎么用?

    相关文章推荐

    • python中ansible是什么?

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网