# Problems with latest elasticsearch-ruby search using point in time

**URL:** <https://discuss.elastic.co/t/problems-with-latest-elasticsearch-ruby-search-using-point-in-time/269646>\
**Category:** Elasticsearch\
**Created:** [April 8, 2021, 10:12pm UTC](https://discuss.elastic.co/t/problems-with-latest-elasticsearch-ruby-search-using-point-in-time/269646 "2021-04-08T22:12:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeffkirk1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jeffkirk1/32/8080_2.png) [@jeffkirk1](https://discuss.elastic.co/u/jeffkirk1)\
**Post date:** [April 8, 2021, 10:12pm UTC](https://discuss.elastic.co/t/problems-with-latest-elasticsearch-ruby-search-using-point-in-time/269646/1 "2021-04-08T22:12:40Z")

</div>

Hey folks,

\< EDITED -- PROBLEM SOLVED -- SEE REPLY BELOW \>

I'm trying to use the elasticsearch-ruby and elasticsearch-xpack Ruby gems to search using the new point in time interface now that the scrolling API has been deprecated.

I am able to create the PIT using the xpack library:

`pit = client.xpack.open_point_in_time(index: es_index, keep_alive: pit_keep_alive)`

According to the Elasticsearch docs, I need to add the pit and the keep\_alive to the JSON I use for my query. Here's my test query

```auto
    {
      "version": true,
      "size": 1000,
      "query": {
        "bool": {
          "must": [
            {
              "match_all": {
              }
            }
          ],
          "filter": [
            {
              "match_phrase": {
                "zip": "87124"
              }
            }
          ],
          "should": [
          ],
          "must_not": [
          ]
        }
      },
      "pit": {
        "id": "m_2xAwYOZmNjX2NlbnN1c19tYXgWb...truncated for space"
      },
      "keep_alive": "5m"
    }

```

This is valid JSON and can be parsed into a Hash object and back again without errors. The pit object is syntactically identical to the format defined in the docs.

When I attempt to search using this query, I get this error from the Elasticsearch client:

```auto
    2.7.2 :072 > response = client.search body: es_body
    Traceback (most recent call last):
            1: from (irb):72
    Elasticsearch::Transport::Transport::Errors::BadRequest ([400] {"error":{"root_cause":[{"type":"parsing_exception","reason":"Unknown key for a VALUE_STRING in [keep_alive].","line":1,"col":969}],"type":"parsing_exception","reason":"Unknown key for a VALUE_STRING in [keep_alive].","line":1,"col":969},"status":400})

```

Using Ruby 2.7.2, Rails 6.1.3, and the latest versions of the elasticsearch, elasticsearch-transport, elasticsearch-api and elasticsearch-xpack gems.

Jeff Kirk

---

<div class="post-metadata">

**Author:** ![jeffkirk1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jeffkirk1/32/8080_2.png) [@jeffkirk1](https://discuss.elastic.co/u/jeffkirk1)\
**Post date:** [April 9, 2021, 11:28am UTC](https://discuss.elastic.co/t/problems-with-latest-elasticsearch-ruby-search-using-point-in-time/269646/2 "2021-04-09T11:28:42Z")

</div>

Never mind, I found the problem; I had not nested the keep\_alive string properly under the "pit" key in the JSON document. Instead I had accidentally put it at the root level. Please disregard.

For the record, the corrected query body is below.

```
{
  "version": true,
  "size": 1000,
  "query": {
    "bool": {
      "must": [
        {
          "match_all": {
          }
        }
      ],
      "filter": [
        {
          "match_phrase": {
            "zip": "87124"
          }
        }
      ],
      "should": [

      ],
      "must_not": [

      ]
    }
  },
  "pit": {
    "id": "m_2xAwYOZmNjX2Nlbn...truncated for space",
    "keep_alive": "5m"
  }
}
```

---

<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 7, 2021, 11:29am UTC](https://discuss.elastic.co/t/problems-with-latest-elasticsearch-ruby-search-using-point-in-time/269646/3 "2021-05-07T11:29:18Z")

</div>

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