zhaohz

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

elasticsearch命令:

显示所有索引: curl http://dv7:9200/_cat/indices?v 

查询:curl http://dv7:9200/corp-base/_search?q=*

删除索引:curl -XDELETE http://dv7:9200/corp-base

 

设置最大返回数

 curl -XPUT  http://dv7:9200/corp-base/_settings -d '{"index":{"max_result_window":"50000000"}}'

curl http://dv7:9200/corp-base/_settings

 

 

python代码:

 

# coding:utf-8

import time

from elasticsearch import Elasticsearch

import sys



from database.mongodb.enterprisedb import EnterpriseDB

from libs.utils import md5string

reload(sys)

sys.setdefaultencoding('utf-8')



if __name__ == "__main__":

    # es = Elasticsearch("dv7")

    # es.index(index="corp-base", doc_type="test-type", id=md5string("中国"),

    #   body={"any":"this is a good day", "timestamp": datetime.now()})

    # ret = es.get(index="corp-base", doc_type="test-type", id=md5string("中国"))['_source']

    # print ret



    es = Elasticsearch("dv7")

    basedb = EnterpriseDB("dv4:27017")

    count = 0

    for item in basedb.find({"updatetime": {'$gt': 0}}):

        del item["_id"]

        es.index(index="corp-base", doc_type="test-type", id=md5string(item["name"]),body=item)

        count = count + 1

        if count%1000 == 0:

            print "%s processing:%s"%(time.asctime(),count)



    print "finished!count:%s"%count

 

 

 

 

posted on 2019-12-29 23:29  zzhaoh  阅读(431)  评论(0编辑  收藏  举报