首页 > 解决方案 > 显示来自不同弹性搜索索引的建议?

问题描述

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

标签: javascriptelasticsearch

解决方案


推荐阅读