【发布时间】:2021-08-12 15:57:22
【问题描述】:
我在 ES 的文档中有一个对象数组
我只想匹配对象(数组内)内的 2 个字段匹配的文档。
我的问题是这个。假设我有 3 个文档(删除了外部文档),其中有一组对象,例如
// Doc 1
"questionAnswers": [
{
"question": "First yes no question",
"answer": "Yes"
},
{
"question": "Second yes no question",
"answer": "No"
}
]
// Doc 2
"questionAnswers": [
{
"question": "First yes no question",
"answer": "No"
},
{
"question": "Second yes no question",
"answer": "No"
}
]
// Doc 3
"questionAnswers": [
{
"question": "First yes no question",
"answer": "No"
},
{
"question": "Second yes no question",
"answer": "Yes"
}
]
我的查询是
{
"from": 0,
"size": 25,
"query": {
"bool": {
"filter": [
{
"match": {
"questionAnswers.question.keyword": "First yes no question"
}
},
{
"match": {
"questionAnswers.answer": "Yes"
}
}
]
}
}
}
我目前正在获取文档 1 和 3 的匹配项。而我只希望第一个文档匹配 where question = First yes no question and answer = Yes
如何做到这一点?
【问题讨论】:
标签: elasticsearch