Records aren't getting queried

I'm learning programming using a book and it is using elasticsearch with it as a project. I am trying to follow along the book but I am getting stuck querying records after bulk uploading records.

For example, I have the following record (which I get via 127.0.0.1:9200/_search)

{
  "took": 8,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "books",
        "_type": "book",
        "_id": "pg123",
        "_score": 1,
        "_source": {
          "doc": {
            "id": 123,
            "title": "At the Earth's Core",
            "authors": [
              "Burroughs, Edgar Rice"
            ],
            "subjects": [
              "Earth (Planet) -- Core -- Fiction",
              "Science fiction",
              "Adventure stories",
              "Fantasy fiction"
            ]
          }
        }
      }
    ]
  }
}

But when I search using this: curl -s -XGET '127.0.0.1:9200/books/book/_search?q=id:123'
I get no hits which is not correct. I expected to get the above response.

{
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 0,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  }
}

Can anyone tell me how to format the query so that it returns the record that I first pasted?

It's because the field name is not id but doc.id.

So this should work:

curl -s -XGET '127.0.0.1:9200/books/book/_search?q=doc.id:123'
1 Like

That worked, thank you so much!

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