显示来自Elasticsearch不同指标的建议?

时间:2018-07-04 06:19:11

标签: javascript elasticsearch

假设我在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 2002Ram 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"]
        }
    }
}

0 个答案:

没有答案