2016-03-07 31 views
1

我跟着文档https://www.elastic.co/guide/en/elasticsearch/guide/current/multi-fields.html添加排序列为名称字段。不幸的是,它不工作elasticsearch排序意外的空返回

这些步骤如下:

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

    然而,在响应排序字段返回

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

    我不知道它为什么不工作,我不能搜索相关的问题文档相关此。是否有人遇到这个问题

    提前感谢

    回答

    2

    你的映射是不正确的。您在索引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" 
         ] 
        } 
    ... 
    
    +0

    啊哈,好去接谢谢:) –