1、今天操作es时查询时添加过滤器,语句如下
- POST _search
- {
- "query": {
- "filtered": {
- "query": {
- "query_string": {
- "query": "drama"
- }
- },
- "filter": {
- "term": {
- "year": 1962
- }
- }
- }
- }
- }
- {
- "error": {
- "root_cause": [
- {
- "type": "parsing_exception",
- "reason": "no [query] registered for [filtered]",
- "line": 3,
- "col": 19
- }
- ],
- "type": "parsing_exception",
- "reason": "no [query] registered for [filtered]",
- "line": 3,
- "col": 19
- },
- "status": 400
- }
查阅相关资料,确认是es当前已经不再支持“filtered”这种写法了
所以改为如下写法:
- POST _search
- {
- "query": {
- "bool": {
- "must": {
- "query_string": {
- "query": "drama"
- }
- },
- "filter": {
- "term": {
- "year": 1962
- }
- }
- }
- }
- }