ElasticSearch:如何为数组字段添加映射?

时间:2016-03-08 01:28:35

标签: elasticsearch

elasticsearch中的示例文档:

{
    "name": "Tom",
    "hobbies": [
        {
            "hobby": "go for a walk"
        },
        {
            "hobby": "board games"
        }
    ]
}

这是为" name"添加的映射:

{
    "person": {
         "_all": {
            "analyzer": "ik_max_word",
            "search_analyzer": "ik_max_word",
            "term_vector": "no",
            "store": "false"
        },
        "properties": {
            "name": {
                "type": "string",
                "store": "no",
                "term_vector": "with_positions_offsets",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word",
                "include_in_all": "true",
                "boost": 8
            }
        }
    }
}

问题:如何为hobbies.hobby添加映射?我想为分析器指定此字段 - > ik_max_word

1 个答案:

答案 0 :(得分:1)

好的,根据Object datatype description,应该这样做:

{
    "person": {
        "_all": {
            "analyzer": "ik_max_word",
            "search_analyzer": "ik_max_word",
            "term_vector": "no",
            "store": "false"
        },
        "properties": {
            "name": {
                "type": "string",
                "store": "no",
                "term_vector": "with_positions_offsets",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word",
                "include_in_all": "true",
                "boost": 8
            },
            "hobbies": {
                "properties": {
                    "hobby": {
                        "type": "string",
                        "store": "no",
                        "term_vector": "with_positions_offsets",
                        "analyzer": "ik_max_word",
                        "search_analyzer": "ik_max_word",
                        "include_in_all": "true",
                        "boost": 8
                    }
                }
            }
        }
    }
}