我已经准备好了这篇文章 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)
答案 0 :(得分:13)
每当在Elastic Search
中执行搜索操作时,都会计算每个匹配文档的相关性。根据文档 -
每个文档的相关性得分由称为
_score
的正浮点数表示。 _score越高,文档越相关。
根据上面提到的例子
GET blablabla/_search
{
"query": {
"multi_match": {
"query": "games usa",
"fields": ["title1", "title2"],
"type": "best_fields"
}
}
}
此查询将在games
或usa
中找到包含title1
AND / OR title2
的文档,但_score
将可以从单个最佳匹配字段计算得出。例如 -
title1
包含games
且title2
在同一文档中包含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
此查询将在usa
或title1
中找到包含title2
AND / OR _score
的文档,但title1
将从所有字段的组合计算。例如 -
games
包含title2
且games 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