简体   繁体   中英

Not sure if my mapping worked in Elasticsearch

Im using ES with my Laravel app using this Elasticquent package.

My mapping looks like this before I index my DB:

'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'
        ],

But when I do the API call _mapping?pretty afterwards

My mapping looks like this:

"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"
                    },

Shouldnt I be able to see 'index' => 'not_analyzed' in my mapping afterwards? Or does 'index' => 'not_analyzed' not show in the map structure afterwards?

You are correct, the mapping did not get applied. You would see the not_analyzed in the mapping API if it was applied correctly.

Make sure that you apply the mapping BEFORE you write any data. We apply the mapping on application startup to verify the mapping is always correct and to apply any mapping updates.

Here is a sample of how to apply a mapping:

PUT hilden1

PUT hilden1/type1/_mapping
{
  "properties": {
    "regular": {
      "type": "string"
    },
    "indexSpecified": {
      "type": "string",
      "index": "not_analyzed"
    }
  }
}

To verify that mapping use the GET api

GET hilden1/type1/_mapping

You should see that the field "regular" only specifies it's type, where as "indexSpecified" is listed as not_analyzed. Here is the output from my machine running ES 1.4.4

{
   "hilden1": {
      "mappings": {
         "type1": {
            "properties": {
               "indexSpecified": {
                  "type": "string",
                  "index": "not_analyzed"
               },
               "regular": {
                  "type": "string"
               }
            }
         }
      }
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM