elasticsearch best_field和most_field之间的区别是什么

时间:2016-02-14 15:59:36

标签: elasticsearch elasticsearch-2.0

我已经准备好了这篇文章 https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html

但我自己也无法弄清楚。

让我们有两个问题:

第一

GET blablabla/_search
{
  "query": {
    "multi_match": {
      "query": "games usa",
      "fields": ["title1", "title2"],
      "type": "best_fields"
    }
  }
}

第二

get blablabla/_search
{
  "query" : {
    "multi_match": {
      "query": "games usa",
      "fields": ["title1", "title2"],
      "type": "most_fields"
    }
  }
}

我认为第一个查询意味着:

  

在title1或title2字段中获取包含(游戏)或(美国)或(游戏和美国)单词的文档。

但是,我不知道第二个意思是什么。

我可以请求帮助吗?

(im on elasticsearch 2.2)

2 个答案:

答案 0 :(得分:13)

每当在Elastic Search中执行搜索操作时,都会计算每个匹配文档的相关性。根据文档 -

  

每个文档的相关性得分由称为_score的正浮点数表示。 _score越高,文档越相关。

根据上面提到的例子

GET blablabla/_search
{
"query": {
"multi_match": {
  "query": "games usa",
  "fields": ["title1", "title2"],
  "type": "best_fields"
   }
  }
}

此查询将在gamesusa中找到包含title1 AND / OR title2的文档,但_score将可以从单个最佳匹配字段计算得出。例如 -

  • 如果title1包含gamestitle2在同一文档中包含games usa,则_score将是title2中的best_fields。< / LI> 当您搜索在同一字段中找到的多个单词时,
  • most_fields最有用。

GET blablabla/_search { "query" : { "multi_match": { "query": "games usa", "fields": ["title1", "title2"], "type": "most_fields" } } }

games

此查询将在usatitle1中找到包含title2 AND / OR _score的文档,但title1将从所有字段的组合计算。例如 -

  • 如果games包含title2games usa在同一文档中包含_score,那么title1将是来自title2的得分组合public class Car { // instance variables - replace the example below with your own private double milesPerGallon; private double fuel; /** * Constructor for objects of class Car */ public Car(double milesPerGallon) { // initializes all instance varibles to starting values this.milesPerGallon = milesPerGallon; //set gas to initial 3.5 fuel = 3.5; } /** * adding gass to instance variable */ public double addGas(double fuel) // takes one parameter from tester, the amount of gas to add to the tank { // increases the amount of gas in the tank this.fuel = this.fuel + fuel; } /** * What is the remaining gas? */ public double drive(double distance) // takes one parameter from tester, the distence in miles that were driven { // calculating the gas // decreases the amount of gas in the tank double leftOverFuel = fuel * milesPerGallon - distance; //distance fuel = (distance / milesPerGallon); // update the instance variabl } /** * When will the car get empty fuel? */ public double range() { // calculates range, the number of miles the car can travel until the gas tank is empty double leftOverFuel; leftOverFuel = fuel * milesPerGallon; // returns the calculations return leftOverFuel; } }

希望这有帮助

答案 1 :(得分:1)

对于most_fields的一点评论 - 它使用两个字段的得分。并将其除以字段数

在你的例子中: (得分为title1 +得分为title2)/ 2