我的index下面有8个分类,company, companyInfo, category,address 这四个都是text类型,Analyzer用的是ik_max_word,剩下四个country,website,phone,URL_ID用的都是keyword类型,现在我的代码是在每次搜索的时候,匹配,company, companyInfo, category这三个type,然后根据score从高到底排序展示.
 
 
															
																				{
                    "query": {
                        "bool": {
                            "should": [
                                {"match": {
                                    "company": key_words
                                }},
                                {"match": {
                                    "companyInfo": key_words
                                }},
                                {"match": {
                                    "category": key_words
                                }}
                            ]
                        }
                    },
                    "from": (page - 1) * 10,
                    "size": 10,
                    "highlight": {
                        "pre_tags": ['<span class="keyWord">'],
                        "post_tags": ['</span>'],
                        "fields": {
                            "company": {},
                            "category": {},
                            "companyInfo": {}
                        }
                    },
                    "collapse": {
                        "field": "phone"
                    },
                    "sort": [
                        {"_score": {"order": "desc"}},
                        {"companyInfo": {"order": "desc", "mode": "max"}}
                    ],
                    "aggs": {
                        "total": {
                            "cardinality": {
                                "field": "phone"
                            }
                        }
                    }
}
 
	
3 个回复
laoyang360 - 《一本书讲透Elasticsearch》作者,Elastic认证工程师 [死磕Elasitcsearch]知识星球地址:http://t.cn/RmwM3N9;微信公众号:铭毅天下; 博客:https://elastic.blog.csdn.net
赞同来自:
2function_score人工干预评分
rochy - rochy_he
赞同来自:
这样搜索的时候使用 function_score_query 结合你上述的搜索,然后将得分 _score 乘以 boost 字段的 value 作为最终得分
可以参考文章:https://blog.csdn.net/dm_vince ... 01721
zz_hello
赞同来自:
https://www.elastic.co/guide/c ... .html
https://www.elastic.co/guide/c ... .html