【问题标题】:Elasticsearch sorting only by alphabetical not by numericElasticsearch 仅按字母排序而不是按数字排序
【发布时间】:2016-01-26 10:09:59
【问题描述】:

我在 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. 戈麦斯-Acebo & Pombo
  3. 阿德尔肖戈达德

这样的结果如何排序?

  1. 阿德尔肖戈达德
  2. BM&A
  3. 戈麦斯-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"
          }
        }
      }
      }
    }
  }
  }
}

【问题讨论】:

标签: php sorting elasticsearch elasticsearch-jdbc-river


【解决方案1】:

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

【讨论】:

  • 当我使用 URL error: "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[U8fk4Ih3SOGSsl0p_aY8ww][jdbc][0]: SearchParseException[[jdbc][0]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"sort":[{"pd_lawFirmName.raw":{"order":"asc"}}]}]]]; nested: SearchParseException[[jdbc][0]: from[-1],size[-1]: Parse Failure [No mapping found for [pd_lawFirmName.raw] in order to sort on]]; }时出现以下错误
  • 您是否按照我的建议更改了映射?
  • 是的,这是我的查询{....,"mappings": { "sorting": { "properties": { "pd_lawFirmName": { "type": "string", "fields": { "raw": { "type": "string", "index": "not_analyzed" } } } } }}}}
  • 您的初始映射 - jdbc - 与您现在提供的完全不同。更新您的帖子并提供您现在的确切映射以及您测试的确切查询。
  • 我指的是 Elasticsearch 中的实际映射:GET /jdbc/_mapping
猜你喜欢
  • 2019-05-16
  • 1970-01-01
  • 1970-01-01
  • 2021-01-30
  • 2021-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多