mapping - 将映射应用于 Elasticsearch 中的子字段

标签 mapping elasticsearch

我无法为“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 或论坛中找到有关执行此操作的任何文档。谁能指出我正确的方向?

最佳答案

查看 mapping 的文档,尤其是关于 object type 的页面. 您只需将 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"   
                                }
                            }
                        }
                    }
                }
            }   
        }
    }
}

关于mapping - 将映射应用于 Elasticsearch 中的子字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18794389/

相关文章:

mapping - knockout 映射导致堆栈溢出

language-agnostic - 什么时候使用 map 有意义?

php - Elasticsearch php api ssl 无法获取本地颁发者证书

python - 使用 Python 对契约(Contract)桥接分数的 elasticsearch json 对象的元素进行计算

elasticsearch - Elasticsearch-按大于特定值的多个字段的总和进行过滤

python - 通过列表理解或映射加速 numpy 数组分配?

java - Hibernate 一对一映射

java - 将 Map<String, List<>> 与 List<> 映射

elasticsearch - .net 的 Elasticsearch

hibernate - 带有Elasticsearch的Hibernate Search中的初始索引崩溃