eLasticsearch在保存时将Java地图内部的字段类型从字符串转换为日期

发布于 2025-01-28 03:08:23 字数 1102 浏览 3 评论 0原文

我有以下索引映射 - 一个称为customfields的字段包含其他字段,例如firstNamelastName

{
  "customFields": {
    "properties": {
      "firstName": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "lastName": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "address": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "dateOfBirth": {
        "type": "date"
      },
    }
  }
}

。 > customfields 是map<字符串,对象>

dateofbirth字段接受yyyy-mm-dd格式中的值,并且是string

但是,当将其保存在Elasticsearch上时,类型将变为date。我一直在调试,在应用程序中没有找到dateofbirth键入到达Elasticsearch之前的更改。

Elasticsearch是否可能在后台更改类型?

I have the following index mapping - a field called customFields contains other fields such as firstName, lastName, etc.

{
  "customFields": {
    "properties": {
      "firstName": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "lastName": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "address": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "dateOfBirth": {
        "type": "date"
      },
    }
  }
}

In my Spring project, customFields is a Map<String, Object>.

The dateOfBirth field accepts values in the YYYY-MM-DD format and is a String.

However, when its being saved on ElasticSearch, the type becomes date. I have been debugging and I haven't found anywhere in the application where the dateOfBirth type changes to date before being sent to ElasticSearch.

Is it possible ElasticSearch changes the type by itself in the background?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失与倦" 2025-02-04 03:08:23

您没有明确定义这些字段的Elasticsearch映射,并且当Elasticsearch看到它们时,它试图将它们与最佳数据类型匹配,因为您的dateofbirth具有yyyy-mm-dd 即使它在“”中包含它,并且您希望它们为text字段,弹性搜索将其映射到date由于其值而导致的字段。

如果要避免这种情况,则需要在您的Elasticsearch索引映射中使用Text数据类型来定义dateofbirth

希望这会有所帮助。

You are not defining the Elasticsearch mapping explicitly for these fields, and when Elasticsearch see them it tries to match them with best data types, as your dateOfBirth is having a YYYY-MM-DD even if its enclosed in "" and you want them to be a text field, Elasticsearch maps it to date field due to its value.

if you want to avoid this, you need to define dateOfBirth explicitly with text data type in your Elasticsearch index mapping.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文