How to boost search based on index type in elasticsearch or lucene?

后端 未结 4 2090
逝去的感伤
逝去的感伤 2021-01-04 11:49

I have three food type indices \"Italian\", \"Spanish\", \"American\". When the user searches \"Cheese\", documents from \"Italian\" appear to come up at the top. Is it poss

相关标签:
4条回答
  • 2021-01-04 12:17

    For query-time boosting, queries (ex. query string) generally have a boost attribute you can set. Alternatively, you can wrap queries in a custom boost factor. I would probably prefer the former, usually.

    0 讨论(0)
  • 2021-01-04 12:30

    If querying several indices at once, it is possible to specify indices boost at the top level of object passed to Search API:

    curl -XGET localhost:9200/italian,spanish,american/_search -d '
    {
        "query":{"term":{"food_type":"cheese"}},
        "indices_boost" : {
            "ilalian" : 1.4,
            "spanish" : 1.3,
            "american" : 1.1
        }
    }'
    

    http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-index-boost.html#search-request-index-boost

    0 讨论(0)
  • 2021-01-04 12:34

    Use a script_score as part of the function score query:

    function_score: {
      script_score: {
        script: "doc['_type'].value == '<your _type>' ? _score * <boost_factor> : _score"
      }
    }
    
    0 讨论(0)
  • 2021-01-04 12:42

    Add a term query with a boost for either the _type field or the _index (or both).

    0 讨论(0)
提交回复
热议问题