弹性搜索:映射未应用于AWS ELK

huangapple go评论70阅读模式
英文:

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"
}
}
}
}
}

huangapple
  • 本文由 发表于 2020年10月16日 16:58:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/64385980.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定