# Elasticsearch query search sort return null

**URL:** <https://discuss.elastic.co/t/elasticsearch-query-search-sort-return-null/256064>\
**Category:** Elasticsearch\
**Created:** [November 20, 2020, 6:10am UTC](https://discuss.elastic.co/t/elasticsearch-query-search-sort-return-null/256064 "2020-11-20T06:10:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![magesh\_kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magesh_kumar/32/79367_2.png) [@magesh\_kumar](https://discuss.elastic.co/u/magesh_kumar)\
**Post date:** [November 20, 2020, 6:10am UTC](https://discuss.elastic.co/t/elasticsearch-query-search-sort-return-null/256064/1 "2020-11-20T06:10:06Z")

</div>

I'm recently upgrade elasticsearch to 7.9.3 version. All are good but sort not working in one of my index called user\_products.

 ![errors](https://us1.discourse-cdn.com/elastic/original/3X/3/3/335a0ced165326ef95497acf58ae327d0c9a26c3.png)

searched query  
curl -X GET "localhost:9200/user\_products/\_search?pretty" -H 'Content-Type: application/json' -d'  
{  
"sort" : [  
{ "3\_raw" : {"order" : "desc"}},  
"\_score"  
],  
"query" : {  
"match" : { "summary.3" : "REF" }  
}  
}  
'  
My index mapping  
Please see the below link to check my mapping  
https://www.codepile.net/pile/D72zJV75

Any help is highly appreciated. Thanks

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 20, 2020, 2:49pm UTC](https://discuss.elastic.co/t/elasticsearch-query-search-sort-return-null/256064/2 "2020-11-20T14:49:31Z")

</div>

Welcome!

Please don't post images of text as they are hard to read, may not display correctly for everyone, and are not searchable.

Instead, paste the text and format it with `</>` icon or pairs of triple backticks (```), and check the preview window to make sure it's properly formatted before posting it. This makes it more likely that your question will receive a useful answer.

It would be great if you could update your post to solve this.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 20, 2020, 2:59pm UTC](https://discuss.elastic.co/t/elasticsearch-query-search-sort-return-null/256064/3 "2020-11-20T14:59:21Z")

</div>

It's always better to share a full simple script which reproduces your problem.  
Here I tried this:

```auto
DELETE test 
PUT test
{
  "mappings": {
    "properties": {
      "3": {
        "type": "text",
        "fielddata": true
      },
      "3_raw": {
        "type": "keyword"
      }
    }
  }
}
POST test/_doc
{
  "3": "REF",
  "3_raw": "REF"
}
POST test/_doc
{
  "3": "FOO",
  "3_raw": "FOO"
}
GET test/_search
{
  "sort": [
    {
      "3_raw": {
        "order": "desc"
      }
    },
    "_score"
  ],
  "query": {
    "match": {
      "3": "REF"
    }
  }
}

```

And this gives me the expected result:

```auto
{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : null,
    "hits" : [
      {
        "_index" : "test",
        "_type" : "_doc",
        "_id" : "xsQo5nUBfcFQk7m1LfKv",
        "_score" : 0.6931471,
        "_source" : {
          "3" : "REF",
          "3_raw" : "REF"
        },
        "sort" : [
          "REF",
          0.6931471
        ]
      }
    ]
  }
}

```

Tested on 7.9.3.

Could you provide a full recreation script as above. It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

---

<div class="post-metadata">

**Author:** ![magesh\_kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magesh_kumar/32/79367_2.png) [@magesh\_kumar](https://discuss.elastic.co/u/magesh_kumar)\
**Post date:** [November 21, 2020, 7:10am UTC](https://discuss.elastic.co/t/elasticsearch-query-search-sort-return-null/256064/4 "2020-11-21T07:10:43Z")

</div>

Hi @dadoonet,

Thanks for you help in the section. your code done a magic. once again thanks man

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 21, 2020, 8:54am UTC](https://discuss.elastic.co/t/elasticsearch-query-search-sort-return-null/256064/5 "2020-11-21T08:54:11Z")

</div>

Could you tell what was the problem?

---

<div class="post-metadata">

**Author:** ![magesh\_kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magesh_kumar/32/79367_2.png) [@magesh\_kumar](https://discuss.elastic.co/u/magesh_kumar)\
**Post date:** [December 8, 2020, 10:19am UTC](https://discuss.elastic.co/t/elasticsearch-query-search-sort-return-null/256064/6 "2020-12-08T10:19:25Z")

</div>

I added the keyword in the last of the word "summary.3\_raw.keyword" it's working

---

<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:** [January 5, 2021, 10:19am UTC](https://discuss.elastic.co/t/elasticsearch-query-search-sort-return-null/256064/7 "2021-01-05T10:19:36Z")

</div>

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