Properly fetch query data
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
def construct_query(index, net, channel, src, num, size):
|
||||
def construct_query(index, net, channel, src, num, size, nicks=None):
|
||||
# Get the initial query
|
||||
extra_must = []
|
||||
extra_should = []
|
||||
extra_should2 = []
|
||||
if num:
|
||||
extra_must.append({"match": {"num": num}})
|
||||
if net:
|
||||
extra_must.append({"match": {"net": net}})
|
||||
if channel:
|
||||
extra_must.append({"match": {"channel": channel}})
|
||||
if nicks:
|
||||
print("NICKS", nicks)
|
||||
for nick in nicks:
|
||||
extra_should2.append({"match": {"nick": nick}})
|
||||
types = ["msg", "notice", "action", "kick", "topic", "mode"]
|
||||
fields = [
|
||||
"nick",
|
||||
@@ -19,11 +25,13 @@ def construct_query(index, net, channel, src, num, size):
|
||||
"net",
|
||||
"src",
|
||||
]
|
||||
if index == "int":
|
||||
fields.append("mtype")
|
||||
query_should = [{"match": {"mtype": x}} for x in types]
|
||||
else:
|
||||
query_should = [{"match": {"type": x}} for x in types]
|
||||
# if index == "int":
|
||||
# fields.append("mtype")
|
||||
# for ctype in types:
|
||||
# extra_should.append({"match": {"mtype": ctype}})
|
||||
# else:
|
||||
# for ctype in types:
|
||||
# extra_should.append({"match": {"type": ctype}})
|
||||
query = {
|
||||
"size": size,
|
||||
"query": {
|
||||
@@ -32,7 +40,12 @@ def construct_query(index, net, channel, src, num, size):
|
||||
{"match": {"src": src}},
|
||||
{
|
||||
"bool": {
|
||||
"should": query_should,
|
||||
"should": [*extra_should],
|
||||
}
|
||||
},
|
||||
{
|
||||
"bool": {
|
||||
"should": [*extra_should2],
|
||||
}
|
||||
},
|
||||
*extra_must,
|
||||
@@ -42,5 +55,5 @@ def construct_query(index, net, channel, src, num, size):
|
||||
"fields": fields,
|
||||
"_source": False,
|
||||
}
|
||||
print("QUERY", query)
|
||||
|
||||
return query
|
||||
|
||||
Reference in New Issue
Block a user