• Python ES操作


    安装:pip install elasticsearch

    Python操作ES查询时,如search操作,源码:search(self, index=None, doc_type=None, body=None, params=None)

    其中index,doc_type,body都好理解,与平时查询时的一样,body为DSL查询语句,

    params即在URL后添加的参数,使用 curl 查询时URL参数如:?size=0   但在python中使用时赋值方式需要将其设为字典,如:params={“size":0},否则查询时会无法解析

    params参数源码注释如下
    :arg params: dictionary of query parameters, will be handed over to the
    underlying :class:`~elasticsearch.Connection` class for serialization
    dsl = {
        'query': {
            'match': {
                'title': 'xxxtitle'
            }
        }
    }
     
    es = Elasticsearch()
    result = es.search(index='news', doc_type='politics', body=dsl,params={"size":0})
    print(json.dumps(result, indent=2, ensure_ascii=False))
  • 相关阅读:
    TC79
    SQL TUNNING
    Oracle PLSQL
    DB String Split sample
    dw websites
    Load xlsx in a folder to RDBMS table with Talend
    Reading WebSites
    SQOOP Load Data from Oracle to Hive Table
    dotnet use regex two samples
    Excel scientific notation issue
  • 原文地址:https://www.cnblogs.com/cmm2016/p/9858158.html
Copyright © 2020-2023  润新知