我在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语句?也许将其发送到日志文件或不在屏幕上打印。有什么想法吗?谢谢你的阅读。
答案 0 :(得分:0)
您在屏幕上看到的行是由于connection/base.py
中的以下@IBOutlet var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.estimatedRowHeight = 100
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.register(UINib(nibName: "TestCell", bundle: Bundle.main), forCellReuseIdentifier: "TestCell")
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension ViewController : UITableViewDataSource, UITableViewDelegate {
func numberOfSections(in tableView: UITableView) -> Int {
return 1;
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TestCell", for: indexPath) as! TestCell
cell.selectionStyle = .none
return cell
}
}
来电所致:
logger.info()
如果您不希望打印出来,只需使用开关 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
)
答案 1 :(得分:0)
在执行弹性搜索查询之前添加以下行,然后POST响应将不会记录到日志文件中,
logging.getLogger('elasticsearch').setLevel(logging.ERROR)