我正在使用 ES v0.90.1。我希望能够使用其中一个字段来提升索引的特定类型的文档。如官方文档中所述,我这样定义了我的映射:
{
"mappings": {
"mytesttype": {
"_boost": {
"name": "doc_boost",
"null_value": 1.0
},
"properties": {
"date_start": {
"type": "date",
"format": "date_time"
},
"date_end": {
"type": "date",
"format": "date_time"
}
}
}
}
}
所以,在我看来,我的意思是我的索引将有一个类型,该类型具有一个名为默认值的mytesttype
文档提升字段。doc_boost
1
这是创建后索引的元数据:
{
state: open
settings: {
index.number_of_shards: 1
index.number_of_replicas: 0
index.version.created: 900199
}
mappings: {
mytesttype: {
_boost: {
null_value: 1
name: doc_boost
}
properties: {
date_end: {
format: date_time
type: date
}
date_start: {
format: date_time
type: date
}
y: {
type: long
}
x: {
type: long
}
}
}
}
aliases: [ ]
}
然后我尝试索引两个文档:
{
"ref": "ref-1",
"date_start": "2013-07-01T00:00:00.000+0000",
"date_end": "2016-07-01T00:00:00.000+0000",
"y": 100,
"x": 100,
"doc_boost": 1.0
}
{
"ref": "ref-2",
"date_start": "2013-07-01T00:00:00.000+0000",
"date_end": "2016-07-01T00:00:00.000+0000",
"y": 100,
"x": 100,
"doc_boost": 2.0
}
doc_boost
除了字段和ref
值之外,这两个文档是相同的。
现在我的目标是做一个简单的请求,该请求将同时获取两个文档,但具有与doc_boost = 2
. 所以这是我的要求:
{
"query": {
"bool": {
"must": [
{
"match": {
"x": {
"query": 100,
"type": "boolean"
}
}
},
{
"match": {
"y": {
"query": 100,
"type": "boolean"
}
}
},
{
"range": {
"date_start": {
"from": null,
"to": "now",
"include_lower": true,
"include_upper": true
}
}
},
{
"range": {
"date_end": {
"from": "now",
"to": null,
"include_lower": true,
"include_upper": true
}
}
}
]
}
}
}
我希望在ref-2
文档上获得更高的分数,但这是我得到的响应以及解释输出:
{
took: 3
timed_out: false
_shards: {
total: 1
successful: 1
failed: 0
}
hits: {
total: 2
max_score: 2
hits: [
{
_shard: 0
_node: 99cl3dO9TFecp3fDiR3e6A
_index: test_elasticsearchtest
_type: mytesttype
_id: mkwrfEswSj-T5x0c5AObuw
_score: 2
_source: {
ref: ref-1
date_start: 2013-07-01T00:00:00.000+0000
date_end: 2016-07-01T00:00:00.000+0000
y: 100
x: 100
doc_boost: 1
}
_explanation: {
value: 2
description: sum of:
details: [
{
value: 0.5
description: ConstantScore(x:[100 TO 100]), product of:
details: [
{
value: 1
description: boost
}
{
value: 0.5
description: queryNorm
}
]
}
{
value: 0.5
description: ConstantScore(y:[100 TO 100]), product of:
details: [
{
value: 1
description: boost
}
{
value: 0.5
description: queryNorm
}
]
}
{
value: 0.5
description: ConstantScore(date_start:[* TO 1374063073249]), product of:
details: [
{
value: 1
description: boost
}
{
value: 0.5
description: queryNorm
}
]
}
{
value: 0.5
description: ConstantScore(date_end:[1374063073249 TO *]), product of:
details: [
{
value: 1
description: boost
}
{
value: 0.5
description: queryNorm
}
]
}
]
}
}
{
_shard: 0
_node: 99cl3dO9TFecp3fDiR3e6A
_index: test_elasticsearchtest
_type: mytesttype
_id: uvtIJ3n2RTad6CHnzENHgA
_score: 2
_source: {
ref: ref-2
date_start: 2013-07-01T00:00:00.000+0000
date_end: 2016-07-01T00:00:00.000+0000
y: 100
x: 100
doc_boost: 2
}
_explanation: {
value: 2
description: sum of:
details: [
{
value: 0.5
description: ConstantScore(x:[100 TO 100]), product of:
details: [
{
value: 1
description: boost
}
{
value: 0.5
description: queryNorm
}
]
}
{
value: 0.5
description: ConstantScore(y:[100 TO 100]), product of:
details: [
{
value: 1
description: boost
}
{
value: 0.5
description: queryNorm
}
]
}
{
value: 0.5
description: ConstantScore(date_start:[* TO 1374063073249]), product of:
details: [
{
value: 1
description: boost
}
{
value: 0.5
description: queryNorm
}
]
}
{
value: 0.5
description: ConstantScore(date_end:[1374063073249 TO *]), product of:
details: [
{
value: 1
description: boost
}
{
value: 0.5
description: queryNorm
}
]
}
]
}
}
]
}
}
两份文件的分数相同。有人可以向我解释我做错了什么吗?