首页 > 解决方案 > 用于查找未回答问题的弹性搜索查询

问题描述

我需要使用字段“user_response”:[]”找到未回答的问题总数。我没有得到任何计数。

我的要求是如果 User_Response 为空白或不可用,那么这应该是我未回答的问题

我在下面的查询中写了这个但没有得到它给我的计数 0

GET/activity_tracking/_search
{
  "size": 0,
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "user_response": "[ ]"
          }
        }
      ]
    }
  }
}

以下是映射细节

{
  "user_response": {
    "properties": {
      "qid": {
        "type": "Keyword",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      }
    }
  }
}

标签: elasticsearchelasticsearch-5

解决方案


在查询中使用存在函数

GET /_search
{
  "query": {
    "bool": {
      "must_not": {
        "exists": {
          "field": "user_response.qid"
        }
      }
    }
  }
}

推荐阅读