如何在没有reindex数据的情况下更新ElasticSearch Mapping?

时间:2017-02-06 08:17:48

标签: java elasticsearch

我使用elasticsearch 2.2.0并创建数据映射如下:

{
"DOCU": {
    "_source": { "excludes" : ["fileAttachment.fileContent", "fileAttachmentFr.fileContent", "fileAttachmentEn.fileContent", "contentBody", "contentBodyFr", "contentBodyEn", "geoLocations.boundaries"] },
    "properties":{
        "id" : { "type" : "string", "store" : "true" },

        "categoryId" : { "type" : "string", "store" : "true" } ,
        "categoryCode" : { "type" : "string", "store" : "true" } ,
        "categoryDesc" : { "type" : "string", "store" : "true" } ,

        "typeId" : { "type" : "string", "store" : "true" } ,
        "typeCode" : { "type" : "string", "store" : "true" } ,
        "typeDesc" : { "type" : "string", "store" : "true" } ,

        "domainId" : { "type" : "string", "store" : "true" } ,
        "domainCode" : { "type" : "string", "store" : "true" } ,
        "domainDesc" : { "type" : "string", "store" : "true" } ,

        "groupId" : { "type" : "string", "store" : "true" } ,
        "groupCode" : { "type" : "string", "store" : "true" } ,
        "groupDesc" : { "type" : "string", "store" : "true" } ,

        "title" : { "type" : "string", "store" : "true" } ,
        "titleFr" : { "type" : "string", "store" : "true" } ,
        "titleEn" : { "type" : "string", "store" : "true" } ,

        "subTitle" : { "type" : "string", "store" : "true" } ,
        "subTitleFr" : { "type" : "string", "store" : "true" } ,
        "subTitleEn" : { "type" : "string", "store" : "true" } ,

        "summary" : { "type" : "string", "store" : "true" } ,
        "summaryFr" : { "type" : "string", "store" : "true" } ,
        "summaryEn" : { "type" : "string", "store" : "true" } ,

        "body" : { "type" : "string", "store" : "true" } ,
        "bodyFr" : { "type" : "string", "store" : "true" } ,
        "bodyKh" : { "type" : "string", "store" : "true" } ,

        "contentBody" : {
            "type" : "attachment",
             "fields": {
                  "content": { "type": "string", "term_vector":"with_positions_offsets", "store": true, "analyzer" : "english"}
             }
        },
        "contentBodyFr" : {
            "type" : "attachment",
             "fields": {
                  "content": { "type": "string", "term_vector":"with_positions_offsets", "store": true, "analyzer" : "french"}
             }
        },
        "contentBodyEn" : {
            "type" : "attachment",
             "fields": {
                  "content": { "type": "string", "term_vector":"with_positions_offsets", "store": true, "analyzer" : "english"}
             }
        },

        "wkfStatusId" : {"type" : "integer", "store" : "true"},

        "owner" : {"type" : "string", "store" : "true"},
        "createdDate": { "type" : "date", "store" : "true", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"},
        "modifiedDate":{ "type" : "date", "store" : "true", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"},

        "rank" : { "type" : "float", "store" : "true" },
        "nbViewed" : { "type" : "integer", "store" : "true" },
        "nbDownloaded" : { "type" : "integer", "store" : "true" },
        "avgRating" : { "type" : "float", "store" : "true" },
        "nbComment" : { "type" : "integer", "store" : "true" },

        "contributors" : {
            "properties":{
                "id" : { "type" : "string", "store" : "true" },
                "type" : { "type" : "string", "store" : "true" } ,
                "contributorId" : { "type" : "string", "store" : "true" } ,
                "contributorName" : { "type" : "string", "store" : "true" } ,
                "orgCatId" : { "type" : "string", "store" : "true" } ,
                "orgTypeId" : { "type" : "string", "store" : "true" } ,
                "orgId" : { "type" : "string", "store" : "true" } ,
                "orgName" : { "type" : "string", "store" : "true" } 
            }
        },

        "projectES" : {
            "properties":{
                "id" : { "type" : "string", "store" : "true" },
                "orgId" : { "type" : "string", "store" : "true" } ,
                "orgName" : { "type" : "string", "store" : "true" } ,
                "startDate": { "type" : "date", "store" : "true", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"},
                "endDate":{ "type" : "date", "store" : "true", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"},
                "website" : { "type" : "string", "store" : "true" },
                "budget" : { "type" : "string", "store" : "true" },
                "funders" : { "type" : "string", "store" : "true", "term_vector": "with_positions_offsets" }
            }
        },

        "organizationES" : {
            "properties":{
                "id" : { "type" : "string", "store" : "true" },
                "categoryId" : { "type" : "string", "store" : "true" } ,
                "categoryDesc" : { "type" : "string", "store" : "true" } ,
                "typeId" : { "type" : "string", "store" : "true" } ,
                "typeDesc" : { "type" : "string", "store" : "true" } ,  
                "shortName" : { "type" : "string", "store" : "true" },
                "website" : { "type" : "string", "store" : "true" },
                "email" : { "type" : "string", "store" : "true" },
                "tel" : { "type" : "string", "store" : "true" },
                "address" : { "type" : "string", "store" : "true" }
            }
        },

        "employeeES" : {
            "properties":{
                "id" : { "type" : "string", "store" : "true" },
                "categoryId" : { "type" : "string", "store" : "true" } ,
                "categoryDesc" : { "type" : "string", "store" : "true" } ,
                "genderId" : { "type" : "string", "store" : "true" } ,
                "genderDesc" : { "type" : "string", "store" : "true" } ,    
                "email" : { "type" : "string", "store" : "true" },
                "tel" : { "type" : "string", "store" : "true" },
                "country" : { "type" : "string", "store" : "true" },
                "city" : { "type" : "string", "store" : "true" },
                "bio" : { "type" : "string", "store" : "true" }
            }
        },

        "memberES" : {
            "properties":{
                "id" : { "type" : "string", "store" : "true" },
                "memberTypeId" : { "type" : "string", "store" : "true" } ,
                "memberTypeDesc" : { "type" : "string", "store" : "true" } ,
                "isOnline" : { "type" : "string", "store" : "true" } ,
                "isPrivate" : { "type" : "string", "store" : "true" } , 
                "individu" : {
                        "properties":{
                            "id" : { "type" : "string", "store" : "true" },
                            "categoryId" : { "type" : "string", "store" : "true" } ,
                            "categoryDesc" : { "type" : "string", "store" : "true" } ,
                            "genderId" : { "type" : "string", "store" : "true" } ,
                            "genderDesc" : { "type" : "string", "store" : "true" } ,    
                            "email" : { "type" : "string", "store" : "true" },
                            "tel" : { "type" : "string", "store" : "true" },
                            "country" : { "type" : "string", "store" : "true" },
                            "city" : { "type" : "string", "store" : "true" },
                            "bio" : { "type" : "string", "store" : "true" }
                        }
                    }
            }
        },

        "urlContent" : {"type" : "string", "store" : "true"},

        "isParsing" : { "type" : "boolean", "store" : "true" } ,
        "isSelfPublished" : { "type" : "boolean", "store" : "true" } ,

        "isPublished" : { "type" : "boolean", "store" : "true" } ,
        "publicationDate" : { "type" : "date", "store" : "true", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"} ,

        "isPublic" : { "type" : "boolean", "store" : "true" } ,
        "isVisible" : { "type" : "boolean", "store" : "true" } ,
        "isLocked" : { "type" : "boolean", "store" : "true" } ,

        "tagNames" : { "type" : "string", "store" : "true", "term_vector": "with_positions_offsets" },

        "geoLocationsNames": { "type" : "string", "store" : "true", "term_vector": "with_positions_offsets" },
        "geoLocations" :{ 
            "properties":{
                 "id"             :   { "type" : "integer", "store" : "true" },
                 "code"           :   { "type" : "string", "store" : "true" },
                 "desc"           :   { "type" : "string", "store" : "true" },
                 "descEn"         :   { "type" : "string", "store" : "true" },
                 "point"          :   { "type" : "geo_point"},
                 "boundaries"     :   { "type" : "geo_shape"}
            },
            "type" : "nested"
        },

        "fileAttachment" : {
            "properties":{
                    "fileContent" : {
                        "type" : "attachment",
                         "fields": {
                              "content": { "type": "string", "term_vector":"with_positions_offsets", "store": true, "analyzer" : "english"}
                         }
                    },
                    "contentType" : { "type" : "string", "store" : "true", "index" : "not_analyzed" },
                    "lastModifiedDate":{ "type" : "date", "store" : "true", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"},
                    "indexing_date": { "type" : "date", "store" : "true", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"},
                    "filesize": { "type" : "long", "store" : "true" },
                    "indexed_chars": { "type" : "long", "store" : "true"},
                    "filename": { "type" : "string", "store" : "true", "index" : "not_analyzed" },
                    "url": { "type" : "string", "store" : "true", "index" : "no" }
            }
        },

        "fileAttachmentEn" : {
            "properties":{
                    "fileContent" : {
                        "type" : "attachment",
                         "fields": {
                              "content": { "type": "string", "term_vector":"with_positions_offsets", "store": true, "analyzer" : "english"}
                         }
                    },
                    "contentType" : { "type" : "string", "store" : "true", "index" : "not_analyzed" },
                    "lastModifiedDate":{ "type" : "date", "store" : "true", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"},
                    "indexing_date": { "type" : "date", "store" : "true", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"},
                    "filesize": { "type" : "long", "store" : "true" },
                    "indexed_chars": { "type" : "long", "store" : "true"},
                    "filename": { "type" : "string", "store" : "true", "index" : "not_analyzed" },
                    "url": { "type" : "string", "store" : "true", "index" : "no" }
            }
        },

        "fileAttachmentFr" : {
            "properties":{
                    "fileContent" : {
                        "type" : "attachment",
                         "fields": {
                              "content": { "type": "string", "term_vector":"with_positions_offsets", "store": true, "analyzer" : "english"}
                         }
                    },
                    "contentType" : { "type" : "string", "store" : "true", "index" : "not_analyzed" },
                    "lastModifiedDate":{ "type" : "date", "store" : "true", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"},
                    "indexing_date": { "type" : "date", "store" : "true", "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"},
                    "filesize": { "type" : "long", "store" : "true" },
                    "indexed_chars": { "type" : "long", "store" : "true"},
                    "filename": { "type" : "string", "store" : "true", "index" : "not_analyzed" },
                    "url": { "type" : "string", "store" : "true", "index" : "no" }
            }
        }
    }

}}

如何从映射中删除排除字段(如下所示):

"_source": { "excludes" : ["fileAttachment.fileContent", "fileAttachmentFr.fileContent", "fileAttachmentEn.fileContent", "contentBody", "contentBodyFr", "contentBodyEn", "geoLocations.boundaries"] }

我不想重新索引我的数据,因为它需要一整天才能完成。 请帮助:)

1 个答案:

答案 0 :(得分:1)

如果不重新编制索引,就无法更改ElasticSearch映射。

但是,您可以查看https://www.elastic.co/blog/changing-mapping-with-zero-downtime

显示了如何以几乎零停机时间重新编制索引