下面是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 "
}
下面是查询
GET /_search
{
"query": {
"query_string": {
"query": "(*Thomas*)"
}
}
}
我的输出将显示第二个文档作为第一个文档,因为它在描述中包含4次“Thomas”
professor.name
赋予更多的权重,它应该首先显示check,如果没有,则检查“professor.email”,然后检查其他属性Python
es.search(index="data", body={"query": {"query_string": {"query": "(*Thomas*)"}}})
不建议使用
query_string
,如ES official documentation:中所述您可以在其中使用Boost
添加带有索引映射、搜索查询和搜索结果的工作示例
索引映射:
搜索查询:
搜索结果:
更新1:
用于搜索
Thomas
或Sachin
的搜索查询更新2:
使用
"operator":"OR"
的多匹配查询相关问题 更多 >
编程相关推荐