# Adding PIT id to the Search request body through Java SDK

**URL:** <https://discuss.elastic.co/t/adding-pit-id-to-the-search-request-body-through-java-sdk/270057>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [April 13, 2021, 7:33pm UTC](https://discuss.elastic.co/t/adding-pit-id-to-the-search-request-body-through-java-sdk/270057 "2021-04-13T19:33:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RapTvin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raptvin/32/86995_2.png) [@RapTvin](https://discuss.elastic.co/u/RapTvin)\
**Post date:** [April 13, 2021, 7:33pm UTC](https://discuss.elastic.co/t/adding-pit-id-to-the-search-request-body-through-java-sdk/270057/1 "2021-04-13T19:33:43Z")

</div>

While fetching paginated results back from elastic search we need to construct a query like this

```
{
  "size": 10000,
  "query": {
    "match" : {
      "user.id" : "elkbee"
    }
  },
  "pit": {
	    "id": "46ToAwMDaWR5BXV1aWQyKwZub2RlXzMAAAAAAAAAACoBYwADaWR4BXV1aWQxAgZub2RlXzEAAAAAAAAAAAEBYQADaWR5BXV1aWQyKgZub2RlXzIAAAAAAAAAAAwBYgACBXV1aWQyAAAFdXVpZDEAAQltYXRjaF9hbGw_gAAAAA==", 
	    "keep_alive": "1m"
  },
  "sort": [ 
    {"@timestamp": "asc"}
  ]
}

```

How to create the same query with the Java API using Rest- High Level Client

```
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
            searchSourceBuilder.query(query);
            searchSourceBuilder.size(20);
            searchSourceBuilder.trackTotalHits(false);
            searchSourceBuilder.pit; ???????? //UNKNOWN

```

Is the above approach correct and how to add the Pit Parameter to the query too?

Please revert ASAP

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 13, 2021, 7:46pm UTC](https://discuss.elastic.co/t/adding-pit-id-to-the-search-request-body-through-java-sdk/270057/2 "2021-04-13T19:46:15Z")

</div>

You already asked a similar question at [Creation of PIT using Rest High Level Client in Java SDK](https://discuss.elastic.co/t/creation-of-pit-using-rest-high-level-client-in-java-sdk/270039).

Let's keep the same discussion in one place. Thanks.

> [@RapTvin](#):
>
> Please revert ASAP

Please be patient in waiting for responses to your question and refrain from pinging multiple times asking for a response or opening multiple topics for the same question. This is a community forum, it may take time for someone to reply to your question. For more information please refer to the [Community Code of Conduct](https://www.elastic.co/community/codeofconduct) specifically the section "Be patient". Also, please refrain from pinging folks directly, this is a forum and anyone that participates might be able to assist you.

If you are in need of a service with an SLA that covers response times for questions then you may want to consider talking to us about a [subscription](https://www.elastic.co/subscriptions).

It's fine to answer on your own thread after 2 or 3 days (not including weekends) if you don't have an answer.

---

<div class="post-metadata">

**Author:** ![RapTvin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raptvin/32/86995_2.png) [@RapTvin](https://discuss.elastic.co/u/RapTvin)\
**Post date:** [April 13, 2021, 7:50pm UTC](https://discuss.elastic.co/t/adding-pit-id-to-the-search-request-body-through-java-sdk/270057/3 "2021-04-13T19:50:52Z")

</div>

This question was unrelated to the previous question as it refers to adding more fields to the search request body so I created a new topic we can continue this discussion on the earlier thread also if it is against the policy.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 13, 2021, 8:24pm UTC](https://discuss.elastic.co/t/adding-pit-id-to-the-search-request-body-through-java-sdk/270057/4 "2021-04-13T20:24:02Z")

</div>

> [@RapTvin](#):
>
> how to add the Pit Parameter to the query too?

I thought your question was related to PIT.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 11, 2021, 8:24pm UTC](https://discuss.elastic.co/t/adding-pit-id-to-the-search-request-body-through-java-sdk/270057/5 "2021-05-11T20:24:26Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
