Home > Software design >  Querying in elasticsearch to get a json object as output
Querying in elasticsearch to get a json object as output

Time:01-21

{
    "key":
    [
        {
            "text": "I noticed when you came up he's even",
            "start": 0.0,
            "duration": 4.68
        },
        {
            "text": "playing with a little bit your your",
            "start": 3.3,
            "duration": 5.07
        }
    ]
}

I have huge amount of files in this format and i have to write a query for only getting the text and its start.But,I'm getting the whole file in which the text is present as output.

if i write the query like this:

{
    "query":
    {
        "term":
        {
            "key.text": "came"
        }
    }
}

then i should get only

{
    "text": "I noticed when you came up he's even",
    "start": 0.0,
    "duration": 4.68
}

as output but Instead im getting the whole file as output.

CodePudding user response:

You need to use the inner hits of nested query to fetch only the item in a array matches your search query.

  • Related