我正在尝试在ElasticSearch中进行关键字搜索。我最初使用这个:
{
"query": {
"filtered": {
"filter": {
"and": [
{
"fquery": {
"query": {
"query_string": {
"query": "Susan Sloan",
"default_operator": "AND"
}
}
}
}
]
}
}
}
但是,我的客户希望first_name和last_name字段中的匹配优先于其他字段中的匹配,例如家庭成员;他们不喜欢Name =“John Smith”和Spouse =“Susan Sloan”在名字=“Susan Sloan”之前出现的结果。所以我尝试将它更改为在first_name和last_name字段上具有最大提升的多匹配查询。
{
"query": {
"filtered": {
"query": {
"bool": {
"must": [
{
"multi_match": {
"fields": [
"first_name^9",
"last_name^9",
"collection.name^7",
"collection.category.name^7",
"record_type.name^7",
"location.city.name^7",
"location.region.name^7",
"location.country.name^7",
"location.country.name^7",
"relationships.first_name^7",
"relationships.last_name^7",
"attributes.name^1",
"original_text^1"
],
"query": "Susan Sloan",
"operator": "AND",
"type": "cross_fields"
}
}
]
}
}
}
}
}
但是,提升似乎没有做任何事情。即使我有first_name =“Susan”和last_name =“Sloan”的记录,我得到的第一个结果是“Abel Conant”,其中“Susan”和“Sloan”出现在original_text字段中。
答案 0 :(得分:1)
制作multi_match
类型cross_fields
:
"query": "Susan Sloan",
"operator": "AND",
"type": "cross_fields"
答案 1 :(得分:0)
除了添加"键入":" cross_fields",我还必须添加" analyzer":"标准"