【发布时间】:2020-11-11 16:22:01
【问题描述】:
下面是索引定义和带有查询的示例记录
***正在寻找匹配名称为“aaa”且日期从 2020-01-01 开始的记录,所以我不应该得到任何记录,因为弹性搜索中没有日期记录 >2020-01-05 *** 但是,通过以下输入,我仍然从弹性搜索中获取记录,就好像它只考虑名称字段查询一样。
创建索引 邮政 http://localhost:9200/gauss_index1/date_format
"mappings": {
"properties": {
"date": {
"type": "date",
"format": "yyyy-MM-dd"
},
"name":{
"type": "text"
}
}
}
}Add records :
PUT http://localhost:9200/gauss_index1/date_format/1
{
"date": "2019-01-05",
"name": "aaa"
}
PUT http://localhost:9200/gauss_index1/date_format/2
{
"date": "2019-02-05",
"name": "bbb"
}
PUT http://localhost:9200/gauss_index1/date_format/3
{
"date": "2019-03-05",
"name": "ccc"
}
Search
POST http://localhost:9200/gauss_index1/date_format/_search
{
"query": {
"function_score": {
"functions": [
{
"gauss": {
"date": {
"origin": "2020-03-01",
"scale": "10d",
"offset": "5d"
}
}
}
],
"query": {
"multi_match": {
"query": "aaa"
"fields": [
"name"
]
}
}
}
}
}
**Returns only record matching with name aaa but as mentioned in gauss origin is march 1 onwards needs to be searched
but I am getting records of only conditin matching name equals "aaa"
【问题讨论】:
-
高斯函数不会排除文档 1,而只是简单地给它打分,因为它的日期超出了定义的高斯边界。这就是功能分数查询的工作方式。你到底想达到什么目的?
-
例如在 Elastisearch db 中添加了“日期”为 2019-01-05,2019-02-05 的多个文档,因此需要找到下一个日期,例如对于查询输入 2019-01-06 和名称为“bbb”,当我按 10 天缩放时,我应该得到 id 为 2 的文档。但在这里我得到了我添加的所有记录。此外,我必须继续增加日期范围,直到获得最接近的匹配日期,即在查询中配置偏移量 5 的原因
标签: elasticsearch elasticsearch-5 elasticsearch-query