大家好,并提前致谢,
我有以下列方式在elasticsearch服务器上编制索引的数据
{
'main_index':{
'type':[{
'name':'john deo',
'type':'accountant',
'description':'john deo is a great person',
'address':'somewhere in the world'
},
{
'name':'calvin kalvin',
'type':'designer',
'description':'calvin kalvin is john deo's best friend',
'address':'somewhere near'
}]
}
}
我的查询是当我搜索great person
时,它还应该返回sub-type
,说name or type or description or address
例如:
http://localhost:9200/some-index/type?q=great person
因此,除了完整的结果,它还应返回其子类型ie:description
。我试过highlighter
但没有用。
请帮忙。
答案 0 :(得分:2)
这个怎么样?
GET /my_index/type/_search?q=great person
{
"highlight": {
"fields": {"name": {},"type": {},"description": {},"address": {}}
}
}
这给了你:
"hits": [
{
"_index": "my_index",
"_type": "type",
"_id": "1",
"_score": 0.10848885,
"_source": {
"name": "john deo",
"type": "accountant",
"description": "john deo is a great person",
"address": "somewhere in the world"
},
"highlight": {
"description": [
"john deo is a <em>great</em> <em>person</em>"
]
}
}
]
如果您在搜索查询中添加“world”(所以q=great person world
),它会为您提供:
"hits": [
{
"_index": "my_index",
"_type": "type",
"_id": "1",
"_score": 0.13287117,
"_source": {
"name": "john deo",
"type": "accountant",
"description": "john deo is a great person",
"address": "somewhere in the world"
},
"highlight": {
"address": [
"somewhere in the <em>world</em>"
],
"description": [
"john deo is a <em>great</em> <em>person</em>"
]
}
}
]