Elasticsearch uri sort by fieldname



如何通过查询URL

在ES 5.4版本中订购特定字段
http://localhost:9200/companies/emp/_search?q=*&sort=name:desc

在这里,我正在搜索EMP并以降序显示EMP名称。我得到了例外

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

有帮助吗?

http://localhost:9200/companies/emp/_search?q =*& stort = name.keyword:desc

您需要在名称之后放置关键字

之所以发生,是因为您试图使用带有"文本"的字段对数据进行分类。正如错误所说,您应该将类型从"文本"更改为"关键字"或启用fieldData,但我建议您阅读此Infohttps://www.elastic.co/guide/guide/en/elasticsearch/eelasticsearch/reference/reference/current/在启用它之前,fielddata.html。

这是对fieldData的一个很好的解释,以及为什么在文本字段上排序不仅仅是框出:https://www.elastic.co/guide/guide/en/elasticsearch/reference/current/fielddata.html

简而言之,文本字段是通过分析仪运行的,您可以在关闭的地方获得搜索的命中,但不是完全匹配的。例如,从上面发布的链接中,您可以搜索"新"或" York"并找到"纽约"的值,因为它是通过分析仪运行的。

如果您的字段是关键字,则必须在 Exact 值上搜索才能找到它。

现在,与排序有关:排序和聚合之类的操作需要知道该字段的 Exact 值,才能在其上执行类似的操作。通过分析仪运行时,分析值存储,而不是确切的值。

我建议您将映射稍微更改,以将两种类型都包含在类型上:

PUT my_index
{
  "mappings": {
    "emp": {
      "properties": {
        "name": { 
          "type": "text",
          "fields": {
            "keyword": { 
              "type": "keyword"
            }
          }
        }
      }
    }
  }
}

最新更新