[英]Optimize MLT elasticsearch query
I want to apply more like this
query, so I use this(python wrapper for elasticsearch): 我想应用
more like this
查询的内容,因此我使用了以下代码(用于Elasticsearch的python包装器):
{
"query": {
"more_like_this": {
"fields": ["title", "content"],
"docs": [
{
"_index": "kavosh",
"_type": "articles",
"_id": str(news_id)
}
]
}
},
"size": 1,
}
but I have many timeout. 但是我有很多超时 so i decided to reduce range of mlt checking to one week.
所以我决定将mlt检查的范围减少到一周。 (Is it effective?) for example adding this:
(是否有效?)例如添加以下内容:
{
"range": {
"publication_date": {
"lte": now,
"gte": now - 1week
}
}
}
How can apply this filter to MLT query and do you have any suggestion to optimize query? 如何将此过滤器应用于MLT查询,您对优化查询有何建议?
You can use below query: 您可以使用以下查询:
{
"query": {
"filtered": {
"query": {
"more_like_this": {
"fields": [
"title",
"content"
],
"docs": [
{
"_index": "kavosh",
"_type": "articles",
"_id": str(news_id)
}
]
}
},
"filter": {
"range": {
"publication_date": {
"lte": "now",
"gte": "now - 1week"
}
}
}
}
}
}
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.