英文:
ElasticSearch: Mapping not applied to AWS ELK
问题
以下是您要翻译的代码部分:
while applying below mapping to my local ElasticSearch 7.4.1
private static void addIndexMapping(RestHighLevelClient client, String indexName) throws IOException {
PutMappingRequest request = new PutMappingRequest(indexName);
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject();
{
builder.startObject("properties");
{
builder.startObject("modifiedDate");
{
builder.field("type", "date").field("format","yyyy-MM-dd HH:mm:ss.SSS");
}
builder.endObject();
}
builder.endObject();
}
builder.endObject();
request.source(builder);
client.indices().putMapping(request, RequestOptions.DEFAULT);
}
i can see below mapping got created
{
"sandbox" : {
"mappings" : {
"modifiedDate" : {
"full_name" : "modifiedDate",
"mapping" : {
"modifiedDate" : {
"type" : "date",
"format" : "yyyy-MM-dd HH:mm:ss.SSS"
}
}
}
}
}
}
but when applying same mapping on AWS elk 7.4.2 i am seeing below mapping
{
"sandbox" : {
"mappings" : {
"modifiedDate" : {
"full_name" : "modifiedDate",
"mapping" : {
"modifiedDate" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}
In my local i have installed ElasticSearch 7.4.1 and in production ElasticSearch 7.4.2. Couldn't understand what is wrong with my code.
英文:
while applying below mapping to my local ElasticSearch 7.4.1
private static void addIndexMapping(RestHighLevelClient client, String indexName) throws IOException {
PutMappingRequest request = new PutMappingRequest(indexName);
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject();
{
builder.startObject("properties");
{
builder.startObject("modifiedDate");
{
builder.field("type", "date").field("format","yyyy-MM-dd HH:mm:ss.SSS");
}
builder.endObject();
}
builder.endObject();
}
builder.endObject();
request.source(builder);
client.indices().putMapping(request, RequestOptions.DEFAULT);
}
i can see below mapping got created
{
"sandbox" : {
"mappings" : {
"modifiedDate" : {
"full_name" : "modifiedDate",
"mapping" : {
"modifiedDate" : {
"type" : "date",
"format" : "yyyy-MM-dd HH:mm:ss.SSS"
}
}
}
}
}
}
but when applying same mapping on AWS elk 7.4.2 i am seeing below mapping
{
"sandbox" : {
"mappings" : {
"modifiedDate" : {
"full_name" : "modifiedDate",
"mapping" : {
"modifiedDate" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}
In my local i have installed ElasticSearch 7.4.1 and in production ElasticSearch 7.4.2. Couldn't understand what is wrong with my code.
答案1
得分: 1
看起来您是在插入第一个文档之前在本地创建了映射。如果您没有这样做,您可能在本地 Elasticsearch 中使用了模板。您可以在这里找到有关模板的更多信息。在您的情况下,模板可能类似于以下内容:
PUT _index_template/template_1
{
"index_patterns": ["te*", "bar*"],
"template": {
"settings": {
"number_of_shards": 1
},
"mappings": {
"properties": {
"modifiedDate": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss.SSS"
}
}
}
}
}
英文:
It seams that you create your mapping in local before inserting first document. If you don't do this, you probably are using template in your local elasticsearch. You can see more information about templates here. In your case, templates would be something look like this:
PUT _index_template/template_1
{
"index_patterns": ["te*", "bar*"],
"template": {
"settings": {
"number_of_shards": 1
},
"mappings": {
"properties": {
"modifiedDate": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss.SSS"
}
}
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论