Closed
Description
Hi. It seems like to_dict()
method of Search
class does not serialize rescore_query
content.
Example code:
search = Search(index=index_name)
positive_query = Q(
"function_score",
query=Q('term', tags='a'),
script_score={"script": "_score * 1"}
)
negative_query = Q(
"function_score",
query=Q('term', tags='b'),
script_score={"script": "_score * -100"}
)
search = search.query(positive_query)
search = search.extra(
rescore={
'window_size': 100,
"query": {
"rescore_query": negative_query
}
}
)
print(search.query().to_dict())
Result:
{
"query": {
"function_score": {
"query": {
"term": {
"tags": "a"
}
},
"functions": [
{
"script_score": {
"script": "_score * 1"
}
}
]
}
},
"rescore": {
"window_size": 100,
"query": {
"rescore_query": FunctionScore(
functions=[
ScriptScore(script="_score * -100")
],
query=Term(tags="b")
)
}
}
}
Expected result:
{
"query": {
"function_score": {
"query": {
"term": {
"tags": "a"
}
},
"functions": [
{
"script_score": {
"script": "_score * 1"
}
}
]
}
},
"rescore": {
"window_size": 100,
"query": {
"rescore_query": {
"function_score": {
"query": {
"term": {
"tags": "b"
}
},
"functions": [
{
"script_score": {
"script": "_score * -100"
}
}
]
}
}
}
}
}
Despite that, search executes properly.
Metadata
Metadata
Assignees
Labels
No labels