Query to the alias with multiple indices

I use one alias for multiple indices and when i do searching i receive the exception "No mapping found for [FieldName] in order to sort on" , but this exception appear for type, which i do not use for searching. Why elastic do searching for all types in alias , if i use specific type?

Aliases:

{
   "test2": {
      "aliases": {
         "alias1": {}
      }
   },
   "test1": {
      "aliases": {
         "alias1": {}
      }
   }
}

Mappings:

{
   "test2": {
  "mappings": {
     "type2": {
        "properties": {
           "field2": {
              "type": "string"
           },
           "field22": {
              "type": "string"
           },
           "field222": {
              "type": "string"
           }
        }
     }
  }
   },
   "test1": {
  "mappings": {
     "type1": {
        "properties": {
           "field1": {
              "type": "string"
           },
           "field11": {
              "type": "string"
           }
        }
     }
  }
   }
}

Query:

POST /alias1/type2/_search
{
"from": 0,
"size": 100,
"sort": [
  "field222"]
}

Result:

{
   "took": 3,
   "timed_out": false,
   "_shards": {
      "total": 10,
      "successful": 5,
      "failed": 5,
      "failures": [
         {
            "shard": 0,
            "index": "test1",
            "node": "lMhjTXnGSmazRBrTUqJy4Q",
            "reason": {
               "type": "search_parse_exception",
               "reason": "No mapping found for [field222] in order to sort on"
            }
         }
      ]
   },
   "hits": {
      "total": 1,
      "max_score": null,
      "hits": [
         {
            "_index": "test2",
            "_type": "type2",
            "_id": "type2_1",
            "_score": null,
            "_source": {
               "field2": "field2",
               "field22": "field22",
               "field222": "field222"
            },
            "sort": [
               "field222"
            ]
         }
      ]
   }
}

Aliases don't pay attention to types, so it'll still try to query both indices.

Do we have any ways to search by type in the alias?

A filtered alias will do it.

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