在字符串搜索 Elasticsearch 上的精确位置

Exactly Position on String Search Elasticsearch

我需要准确匹配我搜索的内容。 假设我们有 3 个具有单个字段 (user.created_at) 且内容如下的文档:

Wed Mar 04 09:14:25 +0000 2020
Wed Mar 25 12:14:25 +0000 2020
Wed Mar 25 06:14:25 +0000 2020

那么我在 RAW 中的查询是

 {
    "query": {
        "bool": {
            "must": [
                {
                    "wildcard": {
                        "user.created_at.keyword": "*2020"
                    }
                },
                {
                    "match": {
                        "user.created_at": "Wed Mar 25"
                    }
                },
                {
                    "match": {
                        "user.created_at": "Wed Mar"
                    }
                },
                {
                    "match": {
                        "user.created_at": "Mar 25"
                    }
                },
                {
                    "match": {
                        "user.created_at": "Wed"
                    }
                },
                {
                    "match": {
                        "user.created_at": "Mar"
                    }
                },
                {
                    "match": {
                        "user.created_at": "25"
                    }
                }
            ]
        }
    }
}

我只想搜索 Wed Mar 25,它可能会发生,我得到的结果一直显示包含 Wed Mar 04 [=30] =] +0000 2020 :

Wed Mar 25 12:14:25 +0000 2020
Wed Mar 25 06:14:25 +0000 2020
Wed Mar 04 09:14:25 +0000 2020

无论如何,字段类型是String,我不知道要更新映射类型。类似

的错误
{
 error: {
  root_cause: [
   {
    type: "resource_already_exists_exception",
    reason: "index [final/KyzdFVn4RnCicyphDFBW-w] already exists",
    index_uuid: "KyzdFVn4RnCicyphDFBW-w",
    index: "final"
   }
  ],
  type: "resource_already_exists_exception",
  reason: "index [final/KyzdFVn4RnCicyphDFBW-w] already exists",
  index_uuid: "KyzdFVn4RnCicyphDFBW-w",
  index: "final"
 },
 status: 400
}

我完全没有想法。请帮助我!

您可以使用倾斜度为 0 的 match_phrase query。此特定查询将确保按顺序找到所有术语。

{
  "query": {
    "bool": {
      "must": [
        {
          "wildcard": {
            "user.created_at.keyword": "*2020"
          }
        },
        {
          "match_phrase": {
            "user.created_at": {
              "slop": 0,
              "query": "Wed Mar 25"
            }
          }
        }
      ]
    }
  }
}

它不会处理所有情况,但在搜索 "Wed Mar 25" 时,您只会得到

Wed Mar 25 12:14:25 +0000 2020
Wed Mar 25 06:14:25 +0000 2020