Elasticsearch: need help with ids filter

I am new to Elasticsearch. I have a mapping that has the following field:

{
  "book": {
    "book": {
      "dynamic": "false",
      "_source": {
        "enabled": true
      },
      "_id": {
        "path": "id"
      },
      "properties": {
        "id": {
          "type": "long",
          "store": "yes",
          "index": "not_analyzed",
          "include_in_all": false
        }
      }
    }
  }
}

I can create an index and add documents. However, when I run the query, for example:

{
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "ids": {
          "type": "long",
          "values" : [10]
        }
      }
    }
  }
}

It does not return anything (the index has a document with id = 10). I am confused by this link :

Can anyone enlighten me on this? What have I done wrong?

+4
source share
1 answer

I understood. The correct way to use the ids filter is as follows:

{
  "query": {
    "filtered": {
      "query": {
        "match_all": {}
      },
      "filter": {
        "ids": {
          "type": "book",
          "values" : [10]
        }
      }
    }
  }
}

The type parameter must be a document type, NOT an id field type . Hope this helps someone else.

+7
source

All Articles