假设我在elasticsearch中有两个索引。第一个names
包含五个值Ram, Shyam, Hari, Dipu, Kishan
,第二个profession
包含五个值,例如teacher, driver, doctor, bank manager, salesman
。当有人输入Ra
时,我想显示类似的建议
Ram is teacher
Ram is driver
Ram is doctor
Ram is bank manager
Ram is salesman
类似地,当有人键入Har
时,我想显示
Hari is teacher
Hari is driver
Hari is doctor
Hari is bank manager
Hari is salesman
我不想存储所有可能的组合。
还假设用户正在寻找Ram is a doctor at Raman Hospital since 2002.
,这里Ram, doctor, Raman Hospital, 2002
属于不同索引。当用户键入Ram
时,我希望显示为Ram is a teacher at Basic Boys School Since 2002
,Ram is salesman at HUL since 2006
的建议。并且如果还有一个名字为Raman
的人,那么Raman is driver at Ola since 2012
也应显示为建议。对于此类搜索,是否有任何好的方法可用,或者我必须努力解决?
映射:
PUT name
{
"mappings": {
"_doc" : {
"properties" : {
"suggest" : {
"type" : "completion",
"contexts": [
{
"name": "userid",
"type": "category"
}
]
}
}
}
}
}
索引:
POST name/_doc/
{
"suggest": {
"input": ["BHANU PRAKASH"],
"contexts": {
"userid": ["99569858","99156661","90273758","6598242461","65910563"]
}
}
}