php - 未分析Elasticsearch无法在排序中工作

标签 php sorting elasticsearch elasticsearch-jdbc-river

我在elasticsearch中添加了“未分析的映射”选项,对结果进行排序时不起作用,这是我使用http://localhost:9200/_river/jdbc/_search时的映射

 "mappings": {
    "jdbc": {
        "dynamic_templates": [
            { "notanalyzed": {
                  "match":              "*", 
                  "match_mapping_type": "string",
                  "mapping": {
                      "type":        "string",
                      "index":       "not_analyzed"
                  }
               }
            }
          ]
       }
   }  

但是,当我对结果进行排序时,它会像
http://localhost:9200/jdbc/_search?pretty=true&sort=field:asc

{ 
    field: "McDermott Will Amery", 
},
sort: [
    "amery"
]
}

但是我需要从字段中的起始单词开始按A-Z顺序排列结果

更新:元数据中的河流规范
http://localhost:9200/_river/jdbc/_meta

{
  "_index": "_river",
  "_type": "jdbc",
  "_id": "_meta",
  "_version": 1,
  "found": true,
  "_source": {
    "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": {
      "jdbc": {
        "dynamic_templates": [
          {
            "notanalyzed": {
              "match": "*",
              "match_mapping_type": "string",
              "mapping": {
                "type": "string",
                "index": "not_analyzed"
              }
            }
          }
        ]
      }
    }
  }
}

最佳答案

我认为您的配置对您要执行的操作不正确。让我们重新开始。首先,让我们删除您的_river索引,然后再次从头开始创建它:

curl -XDELETE localhost:9200/_river

现在让我们再次创建它,但是这次使用correct configuration,即:
  • 您的映射需要在jdbc.type_mapping字段
  • ,您需要指定目标indextype,将数据存储在其中

  • 这是它的样子
    curl -XPUT 'localhost:9200/_river/jdbc/_meta' -d '{
        "type" : "jdbc",
        "jdbc": {
          "driver": "com.mysql.jdbc.Driver",
          "url": "jdbc:mysql://localhost:3306/dbname",
          "user": "user",
          "password": "pass",
          "sql": "SQL QUERY",                  <-- add your 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,
          "index": "your_index",               <-- add this
          "type": "your_type",                 <-- add this
          "type_mapping": {                    <-- add your mapping here
              "your_type": {                   <-- match this with "type" above
                "dynamic_templates": [{
                   "notanalyzed": {
                      "match": "*",
                      "match_mapping_type": "string",
                      "mapping": {
                         "type": "string",
                         "index": "not_analyzed"
                      }
                   }
                }]
             }
          }
        }
    }'
    

    然后,当您的SQL查询运行时,它将数据存储在your_index索引内,并使用your_type映射类型。

    最后,您可以使用以下查询搜索数据:
     curl -XGET 'http://localhost:9200/your_index/your_type/_search?pretty=true&sort=field:asc'
    

    更新

    您还可以使用以下映射定义一个多字段。然后,您就可以在not_analyzed字段上进行排序,并在analyzed上进行搜索:
    "dynamic_templates": [{
       "multi": {
          "match": "*",
          "match_mapping_type": "string",
          "mapping": {
             "type": "string",
             "fields": {
                "raw": {
                   "type": "string",
                   "index": "not_analyzed"
                }
             }
          }
       }
    }]
    

    在名为field的字段上的查询将是
    curl -XGET 'http://localhost:9200/your_index/your_type/_search?pretty=true&q=field:Luke&sort=field.raw:asc'
    

    关于php - 未分析Elasticsearch无法在排序中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33384298/

    相关文章:

    php - 如何在 Symfony 中调试 "MethodNotAllowedHttpException"?

    php - require_once是否打开新连接?

    php - groupBy([]) 不工作

    algorithm - Dijkstra 分区算法 : Special Case

    javascript - 将无限数量的参数传递给 sort() 函数

    elasticsearch - 使用docker启动Titan数据库时出错

    php - 评级算法似乎关闭

    MATLAB 按自定义条件排序

    elasticsearch - 通过NEST进行Elasticsearch:连接到多个主机集群的推荐方法是什么

    java - 为什么ElasticSearch重启后不可用,部分分片未分配?