簡體   English   中英

彈性搜索排序 - 非嵌套元素

[英]Elastic search sorting - Non Nested Elements

我想在彈性搜索中使用排序。 我嘗試了ES 中建議的嵌套排序 - 嵌套排序示例

但后來我發現我的索引擋住了,屬性不是“嵌套”類型。

圖像 - ES 映射

那么對非嵌套類型的內部元素進行排序的最佳方法是什么。

我希望在 MDMGlobalData.City 字段中使用排序

好的,我試圖復制你的問題

PUT my_index
{
  "mappings": {
    "properties": {
      "MDMGlobalData": {
        "properties": {
          "City": {
            "type": "text"
          }
        }
      }
    }
  }
}

用這些插入文檔


POST my_index/_doc
{
  "MDMGlobalData.City":  "Chennai"
  
}
POST my_index/_doc
{
  "MDMGlobalData.City":  "Bangalore"
  
}

試圖用這個排序

GET /my_index/_search
{
  "sort": {
    "MDMGlobalData.City": {
      "order": "asc"
    }
  }
}

收到以下錯誤

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [MDMGlobalData.City] 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."
      }
......

因此我更新了啟用 fielddata 的映射

PUT my_index/_mapping
{
  "properties": {
    "MDMGlobalData": {
      "properties": {
        "City": {
          "type": "text",
          "fielddata": true
        }
      }
    }
  }
}

現在我搜索

GET /my_index/_search
{
  "sort": {
    "MDMGlobalData.City": {
      "order": "asc"
    }
  }
}

它有效

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM