python - Elasticsearch在Python控制台上打印PUT语句

标签 python elasticsearch logging

我已经在Python中编写了以下代码,以使用ElasticSearch对数据执行搜索:

def main():
    start = (time.time())
    es = Elasticsearch()

    es.indices.create(index='bhar',body = {
                                 "settings":{
                                     "analysis":{
                                         "analyzer":{
                                             "my_stop_analyzer":{
                                                 "type":"custom",
                                                 "tokenizer":"standard",
                                                 "filter":["english_possessive_stemmer","lowercase","english_stop","english_stemmer"]
                                                 }
                                             },
                                          "filter":{
                                             "english_stop":{
                                             "type":"stop",
                                             "stopwords":"_english_"
                                             },
                                             "english_stemmer":{
                                             "type":"stemmer",
                                             "name":"english"
                                             },
                                             "english_possessive_stemmer": {
                                             "type":       "stemmer",
                                             "language":   "possessive_english"
                                             }
                                             }
                                             }
                                             },
                                 "mappings":{
                                     "my_type":{
                                         "properties":{
                                             "test": {
                                             "type":"text",
                                             "analyzer" : "my_stop_analyzer"
                                                 }
                                                 }
                                                 }
                                                 }
                                                 })


data = {"rid":"1","test": "This data BHX1 Pick Tower extension"}
res = es.index(index='bhar',doc_type='news',id=1,body=data,refresh=True)

query='pick tower'


match = es.search(index="bhar",body = {
                "query": {
                    "match":{
                        "test":{
                            "query":query.replace('|',' '),
                            "operator" :"AND"
                        }
                    }
                    }
                }
            )
if match['hits']['total']:
        print(match['hits']['hits'][0]['_source'])



if __name__ == '__main__':
    main()

当我执行此代码时,将得到以下输出:
PUT http://localhost:9200/bhar [status:400 request:0.027s]{'rid': '1', 'test': 'This data BHX1 Pick Tower extension'}
如何在屏幕上控制PUT语句?也许将其发送到日志文件,或者只是不将其打印在屏幕上。有什么想法吗?感谢您的阅读。

最佳答案

您在屏幕上看到的行是由于 logger.info() 中的以下connection/base.py调用导致的:

 def log_request_success(self, method, full_url, path, body, status_code, response, duration):
    ...
    logger.info(
        '%s %s [status:%s request:%.3fs]', method, full_url,
        status_code, duration
    )

如果您不希望将其打印出来,只需使用--logging-level=WARN开关运行代码

关于python - Elasticsearch在Python控制台上打印PUT语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43673642/

相关文章:

Python, "filtered"行编辑,通过字符读取标准输入,无回显

arrays - Elasticsearch - 使用嵌套过滤数组作为存储桶

templates - 如何在 Elasticsearch 中为所有 future 字段定义映射

docker - 如何记录在 Docker 容器中运行的所有进程?

python - 使用 XlsxWriter 和 Python Excel 进行循环

python - Numpy 一维数组 - 查找相同数字的子序列的边界索引

python - Pandas 分组日期

spring-boot - 麋鹿 : One or more required cgroup files or directories not found:/proc/self/cgroup

logging - Logger 和 LogWriter 的区别

shell - java.lang.IllegalArgumentException : port out of range:67001