2

i'm facing a problem that how to set "index" : "not_analyzed" globally for the elastic search for string values in mapping json format file so that it will not get tokenized when making reports. Currently i have made that check individually. But,when a new property comes in it creates problem. (using elastic search version 1.7.2)

For example :- If i'm giving a new string field say address, when a value like "bangalore india" comes in, then it will get treated as 2 sepparate values as "Bangalore" and "india" while making reports.

Here is a sample json mapper file format that i'm using. Let me know how i can set it globally for the same..

{
"user" : {
      "_index" : {
         "enabled" : true
     },
     "_id" : {
         "index": "not_analyzed",
         "store" : "yes"
     },
    "properties" : {

         "id" : {
            "type" : "long"
        },
        "name" : {
            "type" : "string",
            "index" : "not_analyzed"
        },
        "presentValue" : {
            "type" : "string",
            "index" : "not_analyzed"
        },
        "dateOfBirth" : {
            "type" : "date" 
        }

    }
}
}
Jesalcv
  • 447
  • 1
  • 5
  • 17

2 Answers2

4

You need to use a dynamic_template when creating your index. With the dynamic strings mapping below, all new string fields that will be created dynamically will be not_analyzed

PUT my_index
{
  "mappings": {
    "user": {
      "_index": {
        "enabled": true
      },
      "_id": {
        "store": "yes"
      },
      "dynamic_templates": [
        {
          "strings": {
            "match_mapping_type": "string",
            "match": "*",
            "mapping": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        }
      ],
      "properties": {
        "id": {
          "type": "long"
        },
        "name": {
          "type": "string",
          "index": "not_analyzed"
        },
        "presentValue": {
          "type": "string",
          "index": "not_analyzed"
        },
        "dateOfBirth": {
          "type": "date"
        }
      }
    }
  }
}
Val
  • 207,596
  • 13
  • 358
  • 360
  • Make sure that, if we are providing the details of existing fields, then we have to specify "index": "not_analyzed" individually otherwise it will override the initial mapping done by dynamic templates. (Or don't give any mapping details of the existing fields that comes as a string.) – Jesalcv Nov 02 '15 at 07:59
0

The following will make sure all fields in index myindex have an extra field as raw

curl -X PUT "http://localhost:9200/myindex" -d '{
  "settings": {
    "index": {
      "number_of_shards": 1,
      "number_of_replicas": 1
    }
  },
  "mapping": {
    "_default_": {
      "dynamic_templates": [
        {
          "multi_strings": {
            "match_mapping_type": "string",
            "mapping": {
              "type": "string",
              "fields": {
                "raw": {
                  "type": "string",
                  "index": "not_analyzed"
                }
              }
            }
          }
        }
      ]
    }
  }
}'
Vineeth Mohan
  • 18,633
  • 8
  • 63
  • 77