gpt4 book ai didi

php - 如何找到在elasticsearch中找到的结果来自哪个子类型?

转载 作者:可可西里 更新时间:2023-10-31 23:30:46 24 4
gpt4 key购买 nike

大家好,提前致谢

我按以下方式在 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时,它还应该返回它的子类型,比如name or type or description or address

例如:

http://localhost:9200/some-index/type?q=great person

因此,除了完整的结果,它还应该返回其子类型,即:description。我试过 highlighter 但没用。

请帮忙。

最佳答案

这个怎么样?

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>"
]
}
}
]

关于php - 如何找到在elasticsearch中找到的结果来自哪个子类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26863216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com