作者disney82231 (小刀会序曲)
看板Python
标题[问题] 有关python的elasticsearch语法
时间Fri Oct 11 23:00:20 2019
小弟因工作需求,刚接触到elasticsearch,所以有些名词可能说的不是很专业
请大家见谅
我现在有一组IP跟port,我在google chorme输入网址的地方,用以下语法搜寻:
IP:port/test_index/_search?q=reason:A|B
可以搜寻到在test_index下reason这个栏位满足A或B的资料。
可是,我在python用elasticsearch的套件用以下语法却抓不出任何东西
body={
"query": {
"bool" :{
"should" : [
{ "term" : { "reason" : "A" } },
{ "term" : { "reason" : "B" } }
]
}
}
}
res = es.search(index='test_index', body=body)
我实在搞不懂,我body的地方哪里有误,也试过好几种写法,就是抓不出来。
另外假设reason只有一个条件的话,用下面语法是可以抓出东西的。
body = {
"query":{
"match":{
"reason":"A"
}
}
}
请大家帮帮忙,谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 36.226.41.46 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1570806022.A.DDF.html
※ 编辑: disney82231 (36.226.41.46 台湾), 10/11/2019 23:01:06
1F:推 luckid: 请问是否方便提供网址回传的json资料以供测试 10/12 12:09