我在Elasticsearch 1.3.4版中有以下查询:
{
"filtered": {
"query": {
"bool": {
"should": [
{
"bool": {
"should": [
{
"match_phrase": {
"_all": "java"
}
},
{
"bool": {
"should": [
{
"match_phrase": {
"_all": "adobe creative suite"
}
}
]
}
}
]
}
},
{
"bool": {
"should": [
{
"nested": {
"path": "skills",
"query": {
"bool": {
"must": [
{
"term": {
"skills.name.original": "java"
}
},
{
"bool": {
"should": [
{
"match": {
"skills.source": {
"query": "linkedin",
"boost": 5
}
}
},
{
"match": {
"skills.source": {
"query": "meetup",
"boost": 5
}
}
}
]
}
}
],
"minimum_should_match": "100%"
}
}
}
}
]
}
}
],
"minimum_should_match": "100%"
}
},
"filter": {
"and": [
{
"bool": {
"should": [
{
"term": {
"skills.name.original": "java"
}
}
]
}
},
{
"bool": {
"should": [
{
"term": {
"skills.name.original": "ajax"
}
},
{
"term": {
"skills.name.original": "html"
}
}
]
}
}
]
}
}
}映射如下所示:
skills: {
type: "nested",
include_in_parent: true,
properties: {
name: {
type: "multi_field",
fields: {
name: {type: "string"},
original: {type : "string", analyzer : "string_lowercase"}
}
}
}
}最后,技能(不包括其他部分)的文档结构如下所示:
"skills":
[
{
"name": "java",
"source": [
"linkedin",
"facebook"
]
},
{
"name": "html",
"source": [
"meetup"
]
}
]我使用这个查询的目标是,首先用过滤器过滤掉一些不相关的匹配(查询的底部),然后通过在整个文档中搜索match_phrase "java“来给一个人打分,如果文档中还包含match_phrase "adobe creative suit",则额外增加分数,然后检查在"skills”中找到的嵌套值,看看技能来自哪种“源”。然后根据嵌套对象具有的源或多个源来增强查询。
这类工作,至少我没有得到任何错误,但最终的分数是奇怪的,很难看到它是否工作。如果我给一个小的提升,比方说2,分数略有下降,我目前的最高分是32.176407分,boost =1。如果提升5分,它会下降到31.637703分。我希望它会上升,而不是下降?随着1000的提升,分数将下降到2.433376。
这是正确的方法吗,还是有更好/更简单的方法?我可以改变结构和映射等。为什么我的分数在下降?
编辑:我稍微简化了查询,只处理了一种“技能”:
{
"filtered": {
"query": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"bool": {
"should": [
{
"match_phrase": {
"_all": "java"
}
}
],
"minimum_should_match": 1
}
}
]
}
}
],
"should": [
{
"nested": {
"path": "skills",
"score_mode": "avg",
"query": {
"bool": {
"must": [
{
"term": {
"skills.name.original": "java"
}
}
],
"should": [
{
"match": {
"skills.source": {
"query": "linkedin",
"boost": 1.2
}
}
},
{
"match": {
"skills.source": {
"query": "meetup",
"boost": 1.2
}
}
}
]
}
}
}
}
]
}
},
"filter": {
"and": [
{
"bool": {
"should": [
{
"term": {
"skills.name.original": "java"
}
}
]
}
}
]
}
}
}现在的问题是,我希望有两个类似的文档,唯一的区别是技能"java“上的"source”值。它们分别是"linkedin“和"meetup”。在我的新查询中,它们都得到了相同的提升,但两个文档的最终_score非常不同。
在单据1的查询说明中:
"value": 3.82485,
"description": "Score based on child doc range from 0 to 125"对于第二个文档:
"value": 2.1993546,
"description": "Score based on child doc range from 0 to 125"这些值是唯一不同的,我不明白为什么。
发布于 2014-10-22 17:29:47
我不能回答关于提升的问题,但是你在索引上有多少分片?TF和IDF是按分片而不是按索引计算的,这可能会造成分数上的差异。https://groups.google.com/forum/#!topic/elasticsearch/FK-PYb43zcQ。
如果只使用1个分片进行重新索引,结果会发生变化吗?
编辑:另外,文档范围是分片中每个文档的文档范围,您可以使用它来计算每个文档的IDF,以验证分数。
https://stackoverflow.com/questions/26263562
复制相似问题