【问题标题】:elasticsearch sorting unexpected null returnedelasticsearch排序意外的null返回
【发布时间】:2016-03-07 11:01:10
【问题描述】:

我按照文档https://www.elastic.co/guide/en/elasticsearch/guide/current/multi-fields.htmlname 字段添加了排序列。不幸的是,它不起作用

这些是步骤:

  1. 添加索引映射
PUT /staff
{
    "mappings": {
        "staff": {
            "properties": {
                "id": {
                    "type":   "string",
                    "index":  "not_analyzed"
                },
                "name": { 
                    "type":     "string",
                    "fields": {
                        "raw": { 
                            "type":  "string",
                            "index": "not_analyzed"
                        }
                    }
                }
            }
        }
    }
}
  1. 添加文档
POST /staff/list {
        "id": 5,
        "name": "abc" 
    }
  1. 搜索 name.raw
POST /staff_change/_search
{
    "sort": "name.raw"
}

但是,响应中的排序字段返回 null

"_source": {
       "id": 5,
        "name": "abc"
    },
    "sort": [
        null
    ]
  }

我不知道为什么它不起作用,我无法搜索与此相关的相关问题文档。有人遇到过这个问题吗

在此先感谢

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您的映射不正确。您在索引staff 内创建一个映射staff,然后在索引staff 内的映射list 下索引文档,该映射有效但使用动态映射,而不是您添加的映射。最后,您正在搜索索引staff 中的所有文档。试试这个:

    PUT /staff
    {
        "mappings": {
            "list": {
                "properties": {
                    "id": {
                        "type":   "string",
                        "index":  "not_analyzed"
                    },
                    "name": { 
                        "type":     "string",
                        "fields": {
                            "raw": { 
                                "type":  "string",
                                "index": "not_analyzed"
                            }
                        }
                    }
                }
            }
        }
    }
    

    然后索引:

    POST /staff/list {
        "id": 5,
        "name": "abc aa" 
    }
    

    并查询:

    POST /staff/list/_search
    {
        "sort": "name.raw"
    }
    

    结果:

    "hits": [
        {
            "sort": [
               "abc aa"
            ]
         }
    ...
    

    【讨论】:

      猜你喜欢
      • 2017-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-26
      • 2014-07-26
      相关资源
      最近更新 更多