使用Elasticsearch数据库中的一些问题

1、今天操作es时查询时添加过滤器,语句如下

  1. POST _search
  2. {
  3.     "query": {
  4.        "filtered": {
  5.           "query": {
  6.              "query_string": {
  7.                 "query""drama"
  8.             }
  9.          },
  10.           "filter": {
  11.              "term": {
  12.                 "year"1962
  13.             }
  14.          }
  15.       }
  16.    }
  17. }
但是出现报错信息,如下:
  1. {
  2.     "error": {
  3.        "root_cause": [
  4.          {
  5.              "type""parsing_exception",
  6.              "reason""no [query] registered for [filtered]",
  7.              "line"3,
  8.              "col"19
  9.          }
  10.       ],
  11.        "type""parsing_exception",
  12.        "reason""no [query] registered for [filtered]",
  13.        "line"3,
  14.        "col"19
  15.    },
  16.     "status"400
  17. }

查阅相关资料,确认是es当前已经不再支持“filtered”这种写法了

所以改为如下写法:

  1. POST _search
  2. {
  3.     "query": {
  4.        "bool": {
  5.           "must": {
  6.              "query_string": {
  7.                 "query""drama"
  8.             }
  9.          },
  10.           "filter": {
  11.              "term": {
  12.                 "year"1962
  13.             }
  14.          }
  15.       }
  16.    }
  17. }

1、今天操作es时查询时添加过滤器,语句如下

  1. POST _search
  2. {
  3.     "query": {
  4.        "filtered": {
  5.           "query": {
  6.              "query_string": {
  7.                 "query""drama"
  8.             }
  9.          },
  10.           "filter": {
  11.              "term": {
  12.                 "year"1962
  13.             }
  14.          }
  15.       }
  16.    }
  17. }
但是出现报错信息,如下:
  1. {
  2.     "error": {
  3.        "root_cause": [
  4.          {
  5.              "type""parsing_exception",
  6.              "reason""no [query] registered for [filtered]",
  7.              "line"3,
  8.              "col"19
  9.          }
  10.       ],
  11.        "type""parsing_exception",
  12.        "reason""no [query] registered for [filtered]",
  13.        "line"3,
  14.        "col"19
  15.    },
  16.     "status"400
  17. }

查阅相关资料,确认是es当前已经不再支持“filtered”这种写法了

所以改为如下写法:

  1. POST _search
  2. {
  3.     "query": {
  4.        "bool": {
  5.           "must": {
  6.              "query_string": {
  7.                 "query""drama"
  8.             }
  9.          },
  10.           "filter": {
  11.              "term": {
  12.                 "year"1962
  13.             }
  14.          }
  15.       }
  16.    }
  17. }

猜你喜欢

转载自blog.csdn.net/weixin_42624312/article/details/81004498
今日推荐