Same field name and mapping but different "index" options?

Hello,

I use ES 2.4.5

In my type mapping, I would need a field named "title", with type always defined as "string", which would be reused several times in different sub-objects or nested sub-objects (i.e. at different levels)

I would like to know if I can use different "index" options (sometimes "analyzed", "not_analyzed" or even "no") depending of the location where the "title" field appears in my whole type mapping

I read and know we cannot change the field type, i.e. from "string" to "integer", but what about the other settings like the "index" option?

Thanks.

Olivier.

Hello,
Not sure to really understand but example below works with a field name title at root of document type (with not_analyzed) and in sub object which is analyzed

PUT test_index

PUT test_index/testType/_mapping
{
  "properties": {
    "Title": {
      "type":"string"
      , "index": "not_analyzed"
    },
    "someObject":
    {
      "type": "object",
      "properties": {
        "someProp":
        {
          "type":"string"
        },
        "Title":{
          "type" : "string"
        }
      }
    }
  }
}

PUT test_index/testType/1
{
  "Title": "some title",
  "someObject": {
    "someProp": "a string",
    "Title": "some title"
  }
}

Then if you test the first request, you'll see that there is no match searching only "some" in root title field because it is not analysed (same search with "some title" will return doc.
Second search will works since field someObject.title is analysed.

GET test_index/testType/_search
{
  "query": {
    "match": {
      "Title": "some"
    }
  }
}
GET test_index/testType/_search
{
  "query": {
    "match": {
      "someObject.Title": "some"
    }
  }
}

Thanks Emmanuel

Your example is not exactly my problem.

To understand better, I changed your example as following:

PUT test_index/testType/_mapping
{
"properties": {
"Title": {
"type":"string"
, "index": "not_analyzed"
},
"someObject":
{
"type": "object",
"properties": {
"someProp":
{
"type":"string"
},
"Title":{
"type" : "string"
"index": "no"
}
}
}
}
}

AFAIK, by default, when omitted, "index" option is equal to "analyzed" and "index": "not_analyzed" is not the same as "index": "no"

So my question is really more about "analyzed/not_analyzed" vs "no" for the same field, in the same document type & index

I hope my problem is more clear now :slight_smile:

Olivier.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.