0

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.

this is my Query:-

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.

Request Body : { "questionTypeId" : "MCMC" }

when questionTypeId = "MCMC" this is the output i am getting..Here I want to exclude the output for which the questionTypeId = "SCMC".

output :

   {
    "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": []
        }
    ]
}
0

1 Answer 1

1

As you have tagged this with :

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.

Sign up to request clarification or add additional context in comments.

4 Comments

How do I get inner hit data? Even if I include innerHit(new InnerHitBuilder()) this statement, I am getting top level document and not the matched inner hit data.
which version of Spring Data Elasticsearch do you use?
I am using -> spring-boot-starter-data-elasticsearch-2.2.6.RELEASE.jar and elasticsearch-core-6.8.7.jar
as I wrote, inner hits are returned in the SearchHits object in the next version 4.1. Spring Boot 2.2.x uses Spring Data Elasticsearch 3.2.x; in that version there is no support for that, you'd need to do your own response parsing there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.