只是一個嘗試,也許它可以讓你開始,你可以進一步實驗:
DELETE /test
PUT /test
{
"mappings": {
"test": {
"dynamic_templates": [
{
"data_template": {
"match": "data",
"mapping": {
"copy_to": "my_custom_all_field",
"term_vector": "with_positions_offsets",
"store": true
}
}
},
{
"inner_fields_of_data_template": {
"path_match": "data.*",
"mapping": {
"copy_to": "my_custom_all_field",
"term_vector": "with_positions_offsets",
"store": true
}
}
}
],
"properties": {
"my_custom_all_field": {
"type": "string",
"term_vector": "with_positions_offsets",
"store": true
}
}
}
}
}
POST /test/test/1
{
"data": {
"fname": "ravinder",
"lastname": "reddy",
"join": "2009-11-15T14:12:12",
"address": {
"Hno": "253",
"Street": "james Street"
}
}
}
POST /test/test/2
{
"data": {
"fname": "ravinder",
"lastname": "james",
"address": {
"Hno": "253",
"Street": "whatever Street"
},
"age": 55
}
}
POST /test/test/3
{
"data": {
"fname": "mui",
"lastname": "reddy",
"address": {
"Hno": "253",
"Street": "james Street"
},
"age": 253
}
}
GET test/test/_search
{
"query": {
"multi_match": {
"query": "james street",
"fields": [
"my_custom_all_field"
],
"type": "phrase_prefix"
}
},
"highlight": {
"fields": {
"data.*": {}
}
}
}
而對於上面的例子,你會得到這樣的輸出:
"hits": [
{
"_index": "test",
"_type": "test",
"_id": "3",
"_score": 0.53423846,
"_source": {
"data": {
"fname": "mui",
"lastname": "reddy",
"address": {
"Hno": "253",
"Street": "james Street"
},
"age": 253
}
},
"highlight": {
"data.address.Street": [
"<em>james Street</em>"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": 0.4451987,
"_source": {
"data": {
"fname": "ravinder",
"lastname": "reddy",
"join": "2009-11-15T14:12:12",
"address": {
"Hno": "253",
"Street": "james Street"
}
}
},
"highlight": {
"data.address.Street": [
"<em>james Street</em>"
]
}
}
]