search script

This commit is contained in:
2023-05-14 20:08:52 +02:00
parent 5c1d62c9f6
commit d921336ff9

View File

@@ -48,14 +48,29 @@ class SearchObject:
self.raw= res.get("_source",{}).get("raw","") self.raw= res.get("_source",{}).get("raw","")
self.highlight=res.get("highlight",{}).get("title",[""]) + res.get("highlight",{}).get("text",[""]) self.highlight=res.get("highlight",{}).get("title",[""]) + res.get("highlight",{}).get("text",[""])
def es_sorting():
return {
"_script": {
"type": "number",
"script": {
"lang": "painless",
"source": "Math.log10(1+doc['updated_at'].value.toInstant().toEpochMilli()/1000000000/100) + Math.log10(1+_score)/10 + Math.log10(1+doc['prio'].value/1000) ", # * Math.log10(1+) * Math.log10(doc['prio'].value/10)" #* doc['_score'].value
},
"order": "desc",
}
}
def es_search(query:str): def es_search(query:str):
logging.debug(f"Run Search for legacy :%s" % query) logging.debug(f"Run Search for legacy :%s" % query)
with es_client() as client: with es_client() as client:
result = client.search( result = client.search(
index = ELASTIC_INDEX, index=ELASTIC_INDEX,
size=10, size=20,
query= es_query(query), query=es_query(query),
highlight = es_highlight() sort=es_sorting(),
highlight=es_highlight(),
) )
logging.debug(result.keys()) logging.debug(result.keys())
return [SearchObject(r) for r in result["hits"]["hits"]] return [SearchObject(r) for r in result["hits"]["hits"]]