querydsl-elasticsearch-must和must不能给出预期的结果

xxslljrj  于 2021-06-15  发布在  ElasticSearch
关注(0)|答案(1)|浏览(310)

ElasticSearch7.8.1
需求获取文档 req_uri property equal to /api/data 而且没有 - in enduser_email 但我收到的结果 -enduser_email 查询dsl

get infolog-2020-08-25/_search
{
  "_source" : ["req_uri","referrer","enduser_email","request_timestamp"],
  "query" : {
    "bool":{
      "must" : [
        {
          "match":{
            "req_uri" : "/api/data"
          }
        }
      ],
      "must_not": [
        {
          "match":{
            "enduser_email":  "-"
          }
        }
      ]
    }
  }
}

我的要求很简单,但我正在elasticsearch中努力解决这个问题
索引Map

lnvxswe2

lnvxswe21#

你应该使用 keyword 子字段:

get infolog-2020-08-25/_search
{
  "_source" : ["req_uri","referrer","enduser_email","request_timestamp"],
  "query" : {
    "bool":{
      "must" : [
        {
          "match":{
            "req_uri.keyword" : "/api/data"
          }
        }
      ],
      "must_not": [
        {
          "match":{
            "enduser_email.keyword":  "-"
          }
        }
      ]
    }
  }
}

相关问题