gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 00:07:44 25 4
gpt4 key购买 nike

我已经在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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com