zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Qt 多线程使用moveToThread
    FFmpeg下载地址
    选择排序
    数据结构和算法之时间复杂度和空间复杂度
    嵌入式动态库查看需要的依赖库
    Q_UNUSED 的使用
    php对csv文件的读取,写入,输出下载操作
    python一个简单的登录
    python的反射
    python类的特性
  • 原文地址:https://www.cnblogs.com/zhaohz/p/12117152.html
Copyright © 2011-2022 走看看