首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ElasticSearch - MoreLikeThis -条件提升

ElasticSearch - MoreLikeThis -条件提升
EN

Stack Overflow用户
提问于 2019-03-16 02:49:21
回答 1查看 159关注 0票数 0

我想根据出版的年份设置不同的“促进条款”,例如:

"boost_term":10.0至2015年后生产

"boost_term":2010 - 2015年间生产的5.0

"boost_term":2010 - 2005年间的3.0版本

以此类推..

代码语言:javascript
复制
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
                        }
                       },
                    ]
                 }
                }
                })
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-16 20:52:06

尝试如下所示:

代码语言:javascript
复制
{
   "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
        }
          }
        }

      ]
    }
  }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55189010

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档