我是一个ElasticSearch菜鸟,我试图弄清楚如何在"标题"字段中提高包含搜索词的搜索结果的相关性.例如,如果有两个文件:
Title="Test Form" Description="This is a new form"
Title="New Form" Description="Test test test"
并且用户在所有字段中搜索"测试",因为搜索项出现在标题字段中,所以文档1应该被提升.
我试图在这里遵循文档,但我不确定我应该包含该命令的上下文.它是应用于索引还是搜索或者?它是否需要成为另一个元素的一部分,还是可以作为单独的命令发布?
这是我到目前为止所做的,5个文档被索引,然后应用提升,最后,在所有字段中搜索字符串"test".
PUT http://localhost:9200//global/Form/456 { "KeyWords": "", "OneLineDesc": "Test", "Link": "", "Title": "Test Form" } PUT http://localhost:9200//global/Form/457 { "KeyWords": "", "OneLineDesc": "", "Link": "", "Title": "Another Form" } PUT http://localhost:9200//global/Form/458 { "KeyWords": "", "OneLineDesc": "test form", "Link": "", "Title": "Ryans Form" } PUT http://localhost:9200//global/Form/460 { "KeyWords": "", "OneLineDesc": "", "Link": "", "Title": "permissions test" } PUT http://localhost:9200//global/Form/576 { "KeyWords": "", "OneLineDesc": "Test test test test test test test test", "Link": "", "Title": "My Test Form" } POST http://localhost:9200//global/Form { "_boost": { "name": "Title", "null_value": 20 } } POST http://localhost:9200/_search?search_type=query_then_fetch { "from": 0, "size": 10, "query": { "match": { "_all": { "query": "test" } } } }
但是,无论是否在索引之后发出boost命令,结果中的分数都是相同的.
我更倾向于在索引编制期间执行此提升操作,因为标题字段将被视为比所有文档中的其他字段更重要.此外,在上面的示例中,每个文档的字段都是常量,但通常情况并非如此,但所有文档都将始终具有标题字段.每个搜索都需要在所有可用字段上执行.