Search 结构化数据弹性搜索中的嵌套字段搜索
我有一个名为data的字段。数据字段动态填充结构化数据。对于结构化数据,我们没有任何先前的固定结构。数据字段包含类型的字符串、日期、整数等数据 结构化数据的示例是Search 结构化数据弹性搜索中的嵌套字段搜索,search,elasticsearch,highlighting,Search,elasticsearch,Highlighting,我有一个名为data的字段。数据字段动态填充结构化数据。对于结构化数据,我们没有任何先前的固定结构。数据字段包含类型的字符串、日期、整数等数据 结构化数据的示例是 "data": { { "fname":"ravinder", "lastname":"reddy", "join":"2009-11-15T14:12:12" "address"" { "Hno": "253", "Street" : "james St
"data":
{
{
"fname":"ravinder",
"lastname":"reddy",
"join":"2009-11-15T14:12:12"
"address""
{
"Hno": "253",
"Street" : "james Street"
}
}
}
如何在该数据字段中搜索特定文本
我应该能够搜索数据字段内的任何文本,并突出显示所选文本
我在搜索中使用了类似data.*的模式。但由于数据字段有多种类型的数据。我在运行时遇到解析异常,所有碎片都无法返回任何内容
我的查询如下所示:
{
"multi_match": {
"query": "james street",
"fields": [
"data",
"data.*"
],
"type": {"phrase_prefix"}
},
"highlight":
{
"fields":{"data","data.*"}
}
}
如果我用_all替换数据,data.*的话,我就可以做到这一点。但我无法突出显示字段
非常感谢您的帮助。非常感谢您只是一次尝试,也许它可以让您开始,您可以进一步尝试:
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>"
]
}
}
]