Wednesday, 18 November 2015

Elasticsearch: Specifying language analyzer


You can specify language analyzer for a field like below.
PUT /blog/_mappings/posts
{
  "properties":{
    "title" :{
      "type" : "string",
      "analyzer":"english"
    }
  }
}


In above case field title uses “English” analyzer instead of default standard analyzer.
GET /blog/_analyze?field=title
{
  "Age is an issue of mind over matter. If you don't mind, it doesn't matter."
}


Response like below.

{
   "tokens": [
      {
         "token": "ag",
         "start_offset": 5,
         "end_offset": 8,
         "type": "<ALPHANUM>",
         "position": 1
      },
      {
         "token": "issu",
         "start_offset": 15,
         "end_offset": 20,
         "type": "<ALPHANUM>",
         "position": 4
      },
      {
         "token": "mind",
         "start_offset": 24,
         "end_offset": 28,
         "type": "<ALPHANUM>",
         "position": 6
      },
      {
         "token": "over",
         "start_offset": 29,
         "end_offset": 33,
         "type": "<ALPHANUM>",
         "position": 7
      },
      {
         "token": "matter",
         "start_offset": 34,
         "end_offset": 40,
         "type": "<ALPHANUM>",
         "position": 8
      },
      {
         "token": "you",
         "start_offset": 45,
         "end_offset": 48,
         "type": "<ALPHANUM>",
         "position": 10
      },
      {
         "token": "don't",
         "start_offset": 49,
         "end_offset": 54,
         "type": "<ALPHANUM>",
         "position": 11
      },
      {
         "token": "mind",
         "start_offset": 55,
         "end_offset": 59,
         "type": "<ALPHANUM>",
         "position": 12
      },
      {
         "token": "doesn't",
         "start_offset": 64,
         "end_offset": 71,
         "type": "<ALPHANUM>",
         "position": 14
      },
      {
         "token": "matter",
         "start_offset": 72,
         "end_offset": 78,
         "type": "<ALPHANUM>",
         "position": 15
      }
   ]
}





Prevoius                                                 Next                                                 Home

No comments:

Post a Comment