# Sorting by \_meta fields

**URL:** <https://discuss.elastic.co/t/sorting-by-meta-fields/119938>\
**Category:** Elasticsearch\
**Created:** [February 15, 2018, 8:28am UTC](https://discuss.elastic.co/t/sorting-by-meta-fields/119938 "2018-02-15T08:28:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vsevolodk](https://avatars.discourse-cdn.com/v4/letter/v/34f0e0/32.png) [@vsevolodk](https://discuss.elastic.co/u/vsevolodk)\
**Post date:** [February 15, 2018, 8:28am UTC](https://discuss.elastic.co/t/sorting-by-meta-fields/119938/1 "2018-02-15T08:28:13Z")

</div>

Hello, please help.  
I have three indices A, B, C and I need multiple search with sorting by index order  
B, A, C. So lexicographical sorting result is not suitable and I want create \_meta field for order  
B - 1  
A - 2  
C - 3

Adding \_meta field

```auto
POST B
{
  "mappings": {
    "user": {
      "_meta": { 
        "sort_order" : 1
      }
    }
  }
}

```

Mapping

```auto
"mappings" : {
      "user" : {
        "_meta" : {
          "sort_order" : 1
        },
        "dynamic_templates" : [
          {
            "string_as_keyword" : {
              "match_mapping_type" : "string",
              "mapping" : {
                "fields" : {
                  "raw" : {
                    "type" : "keyword"
                  }
                },
                "type" : "keyword"
              }
            }
          }
        ],
        "properties" : {
          "foo" : {
            "type" : "keyword",
            "fields" : {
              "raw" : {
                "type" : "keyword"
              }
            }
          }
        }
      }

```

And do sorting via \_meta.sorting\_order.

```auto
POST /B/_search?
{
 "size" : 10000,
 "sort" : [
  { "_meta.sort_order" : {"order" : "asc"} }
 ]
}

```

But I get

```auto
"root_cause": [
            {
                "type": "query_shard_exception",
                "reason": "No mapping found for [_meta.sort_order] in order to sort on",
                "index_uuid": "hJS-64PbS76lZpJduVWhdw",
                "index": "B"
            }
        ]

```

What I do wrong?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 15, 2018, 8:28am UTC](https://discuss.elastic.co/t/sorting-by-meta-fields/119938/2 "2018-03-15T08:28:31Z")

</div>

Closed on March 15, 2018, 8:28am UTC

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