3

I have been using ES 5.4.0 version and created index and documents (student data). when i do search based on age , _search end point is returning value and output is as expected. Did the same for name desc option. i am getting below exception

"error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [name] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "students",
        "node": "MESiRCvSSgqMNWEVwMevMg",
        "reason": {
          "type": "illegal_argument_exception",
          "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [name] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."

what could be the reason. As per log i have to add fileddata=true. any reason behind this.

http://localhost:9200/students/data/_search?q=montana&sort=age:desc - working fine.

http://localhost:9200/students/data/_search?q=montana&sort=name:desc - not working

http://localhost:9200/students/data/_search?q=montana&sort=name:desc&fielddata=true - added fielddata - not wokring

// http://localhost:9200/students?

{
  "students": {
    "aliases": {

    },
    "mappings": {
      "data": {
        "properties": {
          "age": {
            "type": "long"
          },
          "city": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "company": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "email": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "gender": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "name": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "phone": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "state": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "street": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    },
    "settings": {
      "index": {
        "creation_date": "1530174012103",
        "number_of_shards": "5",
        "number_of_replicas": "1",
        "uuid": "PrtajDL0SwS-tTX7Gm_YQw",
        "version": {
          "created": "5040099"
        },
        "provided_name": "students"
      }
    }
  }
}
2
  • Can you share the result you get from curl -XGET localhost:9200/students? (please update your question with the result) Commented Jun 29, 2018 at 7:48
  • @Val.. updated. Commented Jun 29, 2018 at 8:51

1 Answer 1

5

You cannot sort on a text field (you can but the results wouldn't make sense), however, you can sort on a keyword field, so the following query will work:

http://localhost:9200/students/data/_search?q=montana&sort=name.keyword:desc
                                                                   ^
                                                                   |
                                                                add this
Sign up to request clarification or add additional context in comments.

2 Comments

it is working as expected.. Any reason? why we have to use keyword.
Yes, a good reason which is explained here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.