Elasticsearch仅按字母顺序排序,而不是按数字排序

时间:2015-10-27 05:27:04

标签: php sorting elasticsearch elasticsearch-jdbc-river

我在PHP中排序有问题,这是我的映射:

{
  "jdbc": {
    "mappings": {
      "jdbc": {
        "properties": { 
          "admitted_date": {
            "type": "date",
            "format": "dateOptionalTime"
          },
          "et_tax": {
            "type": "string"
          },  
          "jt_tax": {
            "type": "string"
          }, 
          "loc_cityname": {
            "type": "string"
          }, 
          "location_countryname": {
            "type": "string"
          },
          "location_primary": {
            "type": "string"
          },  
          "pd_firstName": {
            "type": "string"
          } 
        }
      }
    }
  }
}

当我按排序使用结果时,它将使用字母数字对结果进行排序,它将首先使用数字加载结果。我只需要开始字母字母排序结果。现在它的订单如下:

  

http://localhost:9200/jdbc/_search?pretty=true&sort=pd_lawFirmName:asc

     
      
  1. BM&安培; A
  2.   
  3. Gomez-Acebo&庞博
  4.   
  5. Addleshaw Goddard
  6.   

如何订购这样的结果?

  
      
  1. Addleshaw Goddard
  2.   
  3. BM&安培; A
  4.   
  5. Gomez-Acebo&庞博
  6.   

这是我用于索引的查询

{
    "type" : "jdbc",
    "jdbc" : {
        "driver" : "com.mysql.jdbc.Driver",
        "url" : "jdbc:mysql://localhost:3306/dbname",
        "user" : "user",
        "password" : "pass",
        "sql" : "SQL QUERY",
        "poll" : "24h",
        "strategy" : "simple", 
        "scale" : 0,
        "autocommit" : true,
        "bulk_size" : 5000,
        "max_bulk_requests" : 30,
        "bulk_flush_interval" : "5s",
        "fetchsize" : 100,
        "max_rows" : 149669,
        "max_retries" : 3,
        "max_retries_wait" : "10s",
        "locale" : "in",
        "digesting" : true,
        "mappings": {
        "sorting": {
        "properties": { 
        "pd_lawFirmName": {
        "type": "string",
        "fields": {
          "raw": {
            "type": "string",
            "index": "not_analyzed"
          }
        }
      }
      }
    }
  }
  }
}

1 个答案:

答案 0 :(得分:2)

这就是因为Elasticsearch将使用默认分析器(standard)对文本进行标记。例如,McDermott Will Amery的索引类似于:

              "amery",
              "mcdermott",
              "will"

如果您想这样排序,我建议您更改pd_lawFirmName的映射,如下所示:

  "pd_lawFirmName": {
    "type": "string",
    "fields": {
      "raw": {
        "type": "string",
        "index": "not_analyzed"
      }
    }
  }

并按raw子字段排序:

http://localhost:9200/jdbc/_search?pretty=true&sort=pd_lawFirmName.raw:asc