5

我无法为“hashtags”创建自定义映射,这是 elasticsearch 中“twitter_entities”的子字段。我尝试通过以下方式做到这一点:

 {
    "mappings": {
        "tweet" : {
            "properties": {
                "twitter_entities.hashtags" : {
                    "type" : "multi_field",
                    "fields" : {
                        "hashtag" : {
                            "type" : "string",
                            "analyzer" : "hashtag"
                        },                        
                        "autocomplete" : {
                            "type" : "string",
                            "index_analyzer" : "hashtag_autocomplete",
                            "search_analyzer" : "hashtag"   
                        }
                    }
                }
            }   
        }
    }
}

这将创建另一个名为“twitter_entities.hashtags”的根字段

 {
    "mappings": {
        "tweet" : {
            "properties": {
                "hashtags" : {
                    "type" : "multi_field",
                    "fields" : {
                        "hashtag" : {
                            "type" : "string",
                            "analyzer" : "hashtag"
                        },                        
                        "autocomplete" : {
                            "type" : "string",
                            "index_analyzer" : "hashtag_autocomplete",
                            "search_analyzer" : "hashtag"   
                        }
                    }
                }
            }   
        }
    }
}

{
    "mappings": {
        "tweet" : {
            "properties": {
                "_parent" : {"type" : "twitter_entities" },
                "hashtags" : {
                    "type" : "multi_field",
                    "fields" : {
                        "hashtag" : {
                            "type" : "string",
                            "analyzer" : "hashtag"
                        },                        
                        "autocomplete" : {
                            "type" : "string",
                            "index_analyzer" : "hashtag_autocomplete",
                            "search_analyzer" : "hashtag"   
                        }
                    }
                }
            }   
        }
    }
}

两者都只是创建另一个名为“hashtags”的根字段。

我无法在 elasticsearch api 或论坛中找到有关执行此操作的任何文档。谁能指出我正确的方向?

4

1 回答 1

10

查看映射文档,尤其是关于对象类型的页面。您只需定义twitter_entities为一个对象并在 下声明其字段properties,就像您为根对象 ( twitter_entities) 所做的一样。您可以省略类型object,因为任何包含其他字段的字段properties都被检测为对象。

{
    "mappings": {
        "tweet" : {
            "properties": {
                "twitter_entities" : {
                    "type": "object",
                    "properties" : {
                        "hashtag" : {
                            "type" : "multi_field",
                            "fields" : {
                                "hashtag" : {
                                "type" : "string",
                                "analyzer" : "hashtag"
                                },                        
                                "autocomplete" : {
                                    "type" : "string",
                                    "index_analyzer" : "hashtag_autocomplete",
                                    "search_analyzer" : "hashtag"   
                                }
                            }
                        }
                    }
                }
            }   
        }
    }
}
于 2013-09-13T21:38:08.250 回答