php - Elasticsearch仅按字母排序而不按数字排序

标签 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. Gomez-Acebo & Pombo
  3. Addleshaw Goddard

如何排序这样的结果?
  1. Addleshaw Goddard
  2. BM&A
  3. Gomez-Acebo & Pombo

这是我用于索引的查询
{
    "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"
          }
        }
      }
      }
    }
  }
  }
}

最佳答案

之所以这样,是因为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

关于php - Elasticsearch仅按字母排序而不按数字排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33360508/

相关文章:

list - 如何逆转Groovy集合的种类?

c++ - kd-tree 构建非常慢

amazon-web-services - 如何通过其其余API更新AWS Elasticsearch集群设置?

elasticsearch - 没有指定字段的简单查询在整个 ElasticSearch 索引中搜索

php - $db = new DB() 混淆

php - SQL 数据库中用户名的默认值

php - 无法与 PayPal 网关通信

javascript - 将 Google Re-CAPTCHA 表单添加到 PHP "Contact us form"

c# - 为什么 List<>.OrderBy LINQ 在 Debug模式下比 IComparable+List<>.Sort 更快?

elasticsearch - elasticsearch-使用logstash日期导入csv未解析为datetime类型