如何在 match_all elasticsearch 中提升字段
How to boost the field in match_all elasticsearch
我需要搜索更多权重 professor.name
那么下一个获取权重的属性是professor.email
检查搜索字符串所在的其他字段
下面是 elasticsearch
中的示例数据
PUT /data/test/1
{
"id": "Accounting 101",
"room": "E3",
"professor": {
"name": "Thomas Baszo",
"email": "baszot@onuni.com"
},
"students_enrolled": 27,
"course_description": " financial statements"
}
PUT /data/test/2
{
"name": "Accounting 101",
"room": "E3",
"professor": {
"name": "Sachin Baszo",
"email": "baszot@onuni.com"
},
"students_enrolled": 27,
"course_description": "Thomas Thomas Thomas Thomas "
}
PUT /data/test/3
{
"name": "Accounting 101",
"room": "E3",
"professor": {
"name": "Sachin Baszo",
"email": "Thomas@onuni.com"
},
"students_enrolled": 27,
"course_description": "Nothing"
}
下面是查询
GET /_search
{"from" : 0, "size" : 100,"query": {"match_all": {}}})
如何实现"fields": [ "professor.name^16", "professor.email^8"]
您可以使用基于匹配查询的 multi_match query 构建以允许 multi-field 查询:
搜索查询:
{
"query": {
"multi_match" : {
"query" : "thomas",
"fields" : [ "professor.name^16", "professor.email^8"]
}
}
}
搜索结果:
"hits": [
{
"_index": "stof_64275333",
"_type": "_doc",
"_id": "1",
"_score": 15.693266,
"_source": {
"id": "Accounting 101",
"room": "E3",
"professor": {
"name": "Thomas Baszo",
"email": "baszot@onuni.com"
},
"students_enrolled": 27,
"course_description": " financial statements"
}
},
{
"_index": "stof_64275333",
"_type": "_doc",
"_id": "3",
"_score": 7.846633,
"_source": {
"name": "Accounting 101",
"room": "E3",
"professor": {
"name": "Sachin Baszo",
"email": "Thomas@onuni.com"
},
"students_enrolled": 27,
"course_description": "Nothing"
}
}
]
我需要搜索更多权重 professor.name
那么下一个获取权重的属性是professor.email
检查搜索字符串所在的其他字段 下面是 elasticsearch
中的示例数据PUT /data/test/1 { "id": "Accounting 101", "room": "E3", "professor": { "name": "Thomas Baszo", "email": "baszot@onuni.com" }, "students_enrolled": 27, "course_description": " financial statements" } PUT /data/test/2 { "name": "Accounting 101", "room": "E3", "professor": { "name": "Sachin Baszo", "email": "baszot@onuni.com" }, "students_enrolled": 27, "course_description": "Thomas Thomas Thomas Thomas " } PUT /data/test/3 { "name": "Accounting 101", "room": "E3", "professor": { "name": "Sachin Baszo", "email": "Thomas@onuni.com" }, "students_enrolled": 27, "course_description": "Nothing" }
下面是查询
GET /_search
{"from" : 0, "size" : 100,"query": {"match_all": {}}})
如何实现"fields": [ "professor.name^16", "professor.email^8"]
您可以使用基于匹配查询的 multi_match query 构建以允许 multi-field 查询:
搜索查询:
{
"query": {
"multi_match" : {
"query" : "thomas",
"fields" : [ "professor.name^16", "professor.email^8"]
}
}
}
搜索结果:
"hits": [
{
"_index": "stof_64275333",
"_type": "_doc",
"_id": "1",
"_score": 15.693266,
"_source": {
"id": "Accounting 101",
"room": "E3",
"professor": {
"name": "Thomas Baszo",
"email": "baszot@onuni.com"
},
"students_enrolled": 27,
"course_description": " financial statements"
}
},
{
"_index": "stof_64275333",
"_type": "_doc",
"_id": "3",
"_score": 7.846633,
"_source": {
"name": "Accounting 101",
"room": "E3",
"professor": {
"name": "Sachin Baszo",
"email": "Thomas@onuni.com"
},
"students_enrolled": 27,
"course_description": "Nothing"
}
}
]