ElasticSearch - MoreLikeThis - Условное повышение - PullRequest
0 голосов
/ 15 марта 2019

Я бы хотел установить разные «условия повышения» в зависимости от года публикации, например:

«boost_term»: 10,0 после 2015 года

«boost_term»: 5,0 к 2010–2015 гг.

«boost_term»: от 3,0 до 2010–2005 гг.

и т. Д. *

Current code:

res = es.search(body={
    "query": { 
        "dis_max": {
            "queries": [
                {
                "more_like_this" : {
                    "fields": [
                        "article.name",
                        "article.year"
                        ],
                        "like" : {
                            "_index" : "test-index",
                            "_type" : "researcher",
                            "_id" : "idResearcher,
                        },
                        "min_term_freq" : 1,
                        "min_doc_freq": 1,
                        "boost_terms": 5.0
                        }
                       },
                    ]
                 }
                }
                })

1 Ответ

0 голосов
/ 16 марта 2019

Попробуйте что-то вроде:

{
   "query": {
      "bool": {
         "must": [
            {
               "more_like_this": {
                  "fields": [
                    "article.name",
                    "article.year"
                  ],
                  "like" : {
                        "_index" : "test-index",
                        "_type" : "researcher",
                        "_id" : "idResearcher",
                    },
                  "min_term_freq": 1,
                  "min_doc_freq": 1
          }
        }
      ],
      "should": [
        {
          "range": {
        "producedYear" : {
            "gte" : "2015",
            "boost" : 10.0
        }
          }
        },
        {
          "range": {
        "producedYear" : {
            "gte" : "2010",
            "lt" : "2015"
            "boost" : 10.0
        }
          }
        },{
          "range": {
        "producedYear" : {
            "gte" : "2005",
            "lt" : "2010"
            "boost" : 3.0
        }
          }
        }

      ]
    }
  }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...