1

I have the following json object

{ "type_name" : 
    {
        "id" : "string"
        "timestamp" : "string"
        "item" : [{"name":"string"}, {...} ...]
    }
}

When I run a query like so,

    lastResponse = client.prepareSearch("index")
            .setSearchType(SearchType.QUERY_AND_FETCH)
            .setQuery(qb)
            .setFrom(0).setSize(60).setExplain(true)
            .execute()
            .actionGet();

The response gives me back a list of type_name that match the query.

Is there a way to have elasticsearch return a single "item" as oppose to the entire type_name?

1 Answer 1

2

Use fields. Using the JSON API this would be as follows:

{
    "fields" : ["id", "timestamp"],
    "query" : {
        "term" : { "id" : "1234567" }
    }
}

If using the Java API, use setFields as follows:

GetResponse response = client.prepareGet(index, type, id)
       .setFields("title")
       .execute()
       .actionGet();

See this forum post for more details.

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

1 Comment

How would I do this using the java api?

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.