如何在弹性搜索中使用查询构建器仅从嵌套类中获取匹配的数据? [英] How to get only matched data from nested class using query builder in elastic search?
问题描述
我试图仅从弹性搜索类的嵌套数组中获取匹配的数据.但我无法得到它......整个嵌套数组数据正在作为输出返回.
I am trying to get only the matched data from nested array of elastic search class. but I am not able to get it..the whole nested array data is being returned as output.
这是我的查询:-
QueryBuilders.nestedQuery(问题",QueryBuilders.boolQuery().must(QueryBuilders.matchQuery(questions.questionTypeId", quesTypeId)), ScoreMode.None).innerHit(new InnerHitBuilder());
QueryBuilders.nestedQuery("questions", QueryBuilders.boolQuery() .must(QueryBuilders.matchQuery("questions.questionTypeId", quesTypeId)), ScoreMode.None) .innerHit(new InnerHitBuilder());
我正在使用查询构建器从嵌套类中获取数据.它工作正常,但无法仅获取匹配的数据.
I am using querybuilders to get data from nested class.Its working fine but not able to get only the matched data.
请求正文:{问题类型 ID":MCMC"}
Request Body : { "questionTypeId" : "MCMC" }
当 questionTypeId = MCMC"时;这是我得到的输出..在这里我想排除 questionTypeId = "SCMC" 的输出.
when questionTypeId = "MCMC" this is the output i am getting..Here I want to exclude the output for which the questionTypeId = "SCMC".
输出:
{
"id": "46",
"subjectId": 1,
"topicId": 1,
"subtopicId": 1,
"languageId": 1,
"difficultyId": 4,
"isConceptual": false,
"examCatId": 3,
"examId": 1,
"usedIn": 1,
"questions": [
{
"id": "46_31",
"pid": 31,
"questionId": "QID41336691",
"childId": "CID1",
"questionTypeId": "MCMC",
"instruction": "This is a single correct multiple choice question.",
"question": "Who holds the most english premier league titles?",
"solution": "Manchester United",
"status": 1000,
"questionTranslation": []
},
{
"id": "46_33",
"pid": 33,
"questionId": "QID41336677",
"childId": "CID1",
"questionTypeId": "SCMC",
"instruction": "This is a single correct multiple choice question.",
"question": "Who holds the most english premier league titles?",
"solution": "Manchester United",
"status": 1000,
"questionTranslation": []
}
]
}
推荐答案
因为你已经用 spring-data-elasticsearch:
最近在 4.1.M1 版本中添加了对返回内部命中的支持,因此将包含在下一个发布版本中.然后在 SearchHit
中,您将获得完整的顶级文档,但在 innerHits
属性中,只会返回匹配的内部命中.
Support to return inner hits was recently added to version 4.1.M1 and so will be included in the next released version. Then in a SearchHit
you will get the complete top level document, but in the innerHits
property only the matching inner hits will be returned.
这篇关于如何在弹性搜索中使用查询构建器仅从嵌套类中获取匹配的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!