mongodb转elasticsearch

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

猜你喜欢

转载自www.cnblogs.com/zhaohz/p/12117152.html
今日推荐