Параметр Elasticsearch Query с ключевым словом сортировки - PullRequest
0 голосов
/ 29 июня 2018

Я использую версию ES 5.4.0 и создал индекс и документы (данные студентов). когда я выполняю поиск по возрасту, конечная точка _search возвращает значение, а результат получается ожидаемым. Сделал то же самое для опции name desc. я получаю ниже исключения

"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."

в чем может быть причина. Согласно журналу я должен добавить fileddata = true. Любая причина этого.

http://localhost:9200/students/data/_search?q=montana&sort=age:desc - работает нормально.

http://localhost:9200/students/data/_search?q=montana&sort=name:desc - не работает

http://localhost:9200/students/data/_search?q=montana&sort=name:desc&fielddata=true - добавлены полевые данные - не работает

// 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"
      }
    }
  }
}

1 Ответ

0 голосов
/ 29 июня 2018

Вы не можете сортировать по полю text (можно, но результаты не имеют смысла), однако вы можете сортировать по полю keyword, поэтому будет работать следующий запрос:

http://localhost:9200/students/data/_search?q=montana&sort=name.keyword:desc
                                                                   ^
                                                                   |
                                                                add this
...