user2722667
user2722667

Reputation: 8661

Elasticsearch wont apply not_analyzed into my mapping

When I try to apply "not_analyzed" into my ES mapping it doesnt work.

I am using this package for ES in Laravel - Elasticquent

My mapping looks like:

'ad_title' => [
            'type' => 'string',
            'analyzer' => 'standard'
        ],
        'ad_type' => [
            'type' => 'integer',
            'index' => 'not_analyzed'
        ],
        'ad_type' => [
            'type' => 'integer',
            'index' => 'not_analyzed'
        ],
        'ad_state' => [
            'type' => 'integer',
            'index' => 'not_analyzed'
        ],

Afterwards I do an API get call to view the mapping and it will output:

"testindex": {
        "mappings": {
            "ad_ad": {
                "properties": {
                    "ad_city": {
                        "type": "integer"
                    },
                    "ad_id": {
                        "type": "long"
                    },
                    "ad_state": {
                        "type": "integer"
                    },
                    "ad_title": {
                        "type": "string",
                        "analyzer": "standard"
                    },
                    "ad_type": {
                        "type": "integer"
                    },

Note that not_analyzed is missing. I cant see any errors/warnings in my logs either.

Upvotes: 1

Views: 354

Answers (2)

hello_its_me
hello_its_me

Reputation: 793

What I gathered from my own experience is that you must do the mapping before you do any indexing. Delete the index you've created, assign your not_analyzed mapper and then index your fields again, and you will have the not_analyzed field appear. Please let me know if this works for you. Thank you.

Upvotes: 1

Jettro Coenradie
Jettro Coenradie

Reputation: 4733

There is an easy test to see if it works:

PUT /stack
{
  "mappings": {
    "try": {
      "properties": {
        "name": {
          "type": "string",
          "index": "not_analyzed"
        }, 
        "age": {
          "type": "integer",
          "index": "not_analyzed"
        }
      }
    }
  }
}

GET /stack/_mapping

and the response is:

{
   "stack": {
      "mappings": {
         "try": {
            "properties": {
               "age": {
                  "type": "integer"
               },
               "name": {
                  "type": "string",
                  "index": "not_analyzed"
               }
            }
         }
      }
   }
}

Upvotes: 1

Related Questions