0

I want to apply more like this query, so I use this(python wrapper for elasticsearch):

{
    "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. (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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.