Problems with latest elasticsearch-ruby search using point in time

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

    {
      "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:

    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

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"
  }
}

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