【发布时间】:2020-02-25 03:23:09
【问题描述】:
我有一个具有以下映射的弹性搜索索引:
PUT /student_detail
{
"mappings" : {
"properties" : {
"id" : { "type" : "long" },
"name" : { "type" : "text" },
"email" : { "type" : "text" },
"age" : { "type" : "text" },
"status" : { "type" : "text" },
"tests":{ "type" : "nested" }
}
}
}
存储的数据格式如下:
{
"id": 123,
"name": "Schwarb",
"email": "abc@gmail.com",
"status": "current",
"age": 14,
"tests": [
{
"test_id": 587,
"test_score": 10
},
{
"test_id": 588,
"test_score": 6
}
]
}
我希望能够查询学生的姓名,如 '%warb%' 和电子邮件,如 '%gmail.com%' 和 id 587 的测试得分 > 5 等。所需的高水平可以是把类似下面的东西,不知道实际的查询是什么,为下面这个混乱的查询道歉
GET developer_search/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"name": "abc"
}
},
{
"nested": {
"path": "tests",
"query": {
"bool": {
"must": [
{
"term": {
"tests.test_id": IN [587]
}
},
{
"term": {
"tests.test_score": >= some value
}
}
]
}
}
}
}
]
}
}
}
查询必须灵活,以便我们可以输入动态测试 ID 及其各自的分数过滤器以及年龄、姓名、状态等嵌套字段之外的字段
【问题讨论】:
标签: elasticsearch elastic-stack