项目有如下需求:
1、模糊关键词查询 elasticsearch
2、对查询出来的结果 进行筛选
我两次都有 elasticsearch 第二次 结果反而比第一次数据要多。今天研究了一下,没有解决以下是一下sql
原始查询语句:
GET /candidates/all/_search
{
"size": "1000",
"query": {
"bool": {
"should": [
{
"match": {
"deliName": {
"minimum_should_match": "70%",
"operator": "or",
"query": "数据科学家"
}
}
},
{
"match": {
"deliCorp": {
"minimum_should_match": "70%",
"operator": "or",
"query": "数据科学家"
}
}
}
],
"must": [
{
"range": {
"startworkingyear": {
"lt": 2012
}
}
}
]
}
}
}
有个朋友帮忙改成如下语句:
GET /candidates/all/_search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"and": [
{
"or": [
{
"match": {
"deliName": {
"minimum_should_match": "70%",
"query": "数据科学家"
}
}
},
{
"match": {
"deliCorp": {
"minimum_should_match": "70%",
"query": "数据科学家"
}
}
}
]
},
{
"range": {
"startworkingyear": {
"lt": 2012
}
}
}
]
}
}
},
"size": 1000
}
报错:
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "no [query] registered for [filtered]",
"line": 3,
"col": 17
}
],
"type": "parsing_exception",
"reason": "no [query] registered for [filtered]",
"line": 3,
"col": 17
},
"status": 400
}
改造成以下语句报错
GET /candidates/all/_search
{
"size": 1000,
"query": {
"filtered": {
"query": {
"bool": {
"should": [
{
"match": {
"deliJob": {
"minimum_should_match": "70%",
"operator": "or",
"query": "数据科学家"
}
}
},
{
"match": {
"deliCorp": {
"minimum_should_match": "70%",
"operator": "or",
"query": "数据科学家"
}
}
}
]
}
}
},
"filter": {
"range": {
"startworkingyear": {
"lt": 2012
}
}
}
}
}
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "no [query] registered for [filtered]",
"line": 4,
"col": 17
}
],
"type": "parsing_exception",
"reason": "no [query] registered for [filtered]",
"line": 4,
"col": 17
},
"status": 400
}
1、模糊关键词查询 elasticsearch
2、对查询出来的结果 进行筛选
我两次都有 elasticsearch 第二次 结果反而比第一次数据要多。今天研究了一下,没有解决以下是一下sql
原始查询语句:
GET /candidates/all/_search
{
"size": "1000",
"query": {
"bool": {
"should": [
{
"match": {
"deliName": {
"minimum_should_match": "70%",
"operator": "or",
"query": "数据科学家"
}
}
},
{
"match": {
"deliCorp": {
"minimum_should_match": "70%",
"operator": "or",
"query": "数据科学家"
}
}
}
],
"must": [
{
"range": {
"startworkingyear": {
"lt": 2012
}
}
}
]
}
}
}
有个朋友帮忙改成如下语句:
GET /candidates/all/_search
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"and": [
{
"or": [
{
"match": {
"deliName": {
"minimum_should_match": "70%",
"query": "数据科学家"
}
}
},
{
"match": {
"deliCorp": {
"minimum_should_match": "70%",
"query": "数据科学家"
}
}
}
]
},
{
"range": {
"startworkingyear": {
"lt": 2012
}
}
}
]
}
}
},
"size": 1000
}
报错:
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "no [query] registered for [filtered]",
"line": 3,
"col": 17
}
],
"type": "parsing_exception",
"reason": "no [query] registered for [filtered]",
"line": 3,
"col": 17
},
"status": 400
}
改造成以下语句报错
GET /candidates/all/_search
{
"size": 1000,
"query": {
"filtered": {
"query": {
"bool": {
"should": [
{
"match": {
"deliJob": {
"minimum_should_match": "70%",
"operator": "or",
"query": "数据科学家"
}
}
},
{
"match": {
"deliCorp": {
"minimum_should_match": "70%",
"operator": "or",
"query": "数据科学家"
}
}
}
]
}
}
},
"filter": {
"range": {
"startworkingyear": {
"lt": 2012
}
}
}
}
}
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "no [query] registered for [filtered]",
"line": 4,
"col": 17
}
],
"type": "parsing_exception",
"reason": "no [query] registered for [filtered]",
"line": 4,
"col": 17
},
"status": 400
}
1 个回复
yangruideyang
赞同来自: