Nested/non nested property in similar mappings

Hi all,
As general overview, we have monthly indexes ("index_2017.01", "index_2017.02", etc...) under the same alias ("index_all") and we monthly add a new index.

Now I'd need to change a property from non nested to nested (let's say cross indexes) and I don't know if this could brake something.

My idea is to deploy the new mapping - with the nested property - to the next month index and add the alias as well, but leaving the old indexes as they are, so basically everything will remain the same, but the involved property.

What kind of strange behavior / incoherence could I expect going with this?

Thank you very much.

You obviously can't use a nested query across both old and new indices, because the old field isn't mapped as nested. If you do try to do that, you'll get an exception reported in the shards section of the old index, but you'll still get results from the new index, eg:

PUT t1
{
  "mappings": {
    "t": {
      "properties": {
        "foo": {
          "type": "object"
        }
      }
    }
  }
}

PUT t2
{
  "mappings": {
    "t": {
      "properties": {
        "foo": {
          "type": "nested"
        }
      }
    }
  }
}

PUT t1/t/1
{
  "foo": {
    "bar": "baz"
  }
}

PUT t2/t/2
{
  "foo": {
    "bar": "baz"
  }
}

GET t*/_search
{
  "query": {
    "nested": {
      "path": "foo",
      "query": {
        "match": {
          "foo.bar": "baz"
        }
      }
    }
  }
}

returns:

{
  "took": 12,
  "timed_out": false,
  "_shards": {
    "total": 10,
    "successful": 5,
    "failed": 5,
    "failures": [
      {
        "shard": 0,
        "index": "t1",
        "node": "OEftVv31Tfuvi9_v10ohVA",
        "reason": {
          "type": "query_shard_exception",
          "reason": """
failed to create query: {
  "nested" : {
    "query" : {
      "match" : {
        "foo.bar" : {
          "query" : "baz",
          "operator" : "OR",
          "prefix_length" : 0,
          "max_expansions" : 50,
          "fuzzy_transpositions" : true,
          "lenient" : false,
          "zero_terms_query" : "NONE",
          "boost" : 1.0
        }
      }
    },
    "path" : "foo",
    "ignore_unmapped" : false,
    "score_mode" : "avg",
    "boost" : 1.0
  }
}
""",
          "index_uuid": "HWb99ARUSGOQi0ZisNV9vw",
          "index": "t1",
          "caused_by": {
            "type": "illegal_state_exception",
            "reason": "[nested] nested object under path [foo] is not of nested type"
          }
        }
      }
    ]
  },
  "hits": {
    "total": 1,
    "max_score": 0.2876821,
    "hits": [
      {
        "_index": "t2",
        "_type": "t",
        "_id": "2",
        "_score": 0.2876821,
        "_source": {
          "foo": {
            "bar": "baz"
          }
        }
      }
    ]
  }
}

Got it!
I'll go with a new property so I can avoid nesting. (alternatively I would reindex too many documents, but we choose to not do like that).

Thank you very much!

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