Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch: needs help on ids filter

I am new to Elasticsearch. I have a mapping which 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 am able to create the index and add documents. However, when I run query such as:

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

It returns nothing (the index has a document with id = 10). I am confused by this link:

Can anyone enlighten me on this? What I did is wrong?

like image 890
curious1 Avatar asked Mar 18 '23 23:03

curious1


1 Answers

I got it figured out. The correct way of using ids filter is as follows:

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

The type parameter should be the document type, NOT the type of the id field. Hope this helps someone else.

like image 133
curious1 Avatar answered Mar 31 '23 00:03

curious1