Monday 16 November 2015

Elasticsearch: Wildcard query

“wildcard” query supports wild cards.

For Example,
Wildcard ‘*’ matches zero/more characters.
Wildcard ‘?’ matches one character.

GET /books/titles/_search
{
  "query":{
    "wildcard":{
      "title" : "L*"
    }
  }
}


Above query matches all documents, where title starts with L.

{
   "took": 12,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 2,
      "max_score": 1,
      "hits": [
         {
            "_index": "books",
            "_type": "titles",
            "_id": "6",
            "_score": 1,
            "_source": {
               "id": 6,
               "title": "Love, Freedom, and Aloneness: The Koan of Relationships"
            }
         },
         {
            "_index": "books",
            "_type": "titles",
            "_id": "7",
            "_score": 1,
            "_source": {
               "id": 7,
               "title": "Life, Love, Laughter: Celebrating Your Existence"
            }
         }
      ]
   }
}

Note:
“title” is not analyzed field in this example.


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment