Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting Elasticsearch:按字母顺序排列西班牙语双名_Sorting_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Alphabetical - Fatal编程技术网 elasticsearch,alphabetical,Sorting,elasticsearch,Alphabetical" /> elasticsearch,alphabetical,Sorting,elasticsearch,Alphabetical" />

Sorting Elasticsearch:按字母顺序排列西班牙语双名

Sorting Elasticsearch:按字母顺序排列西班牙语双名,sorting,elasticsearch,alphabetical,Sorting,elasticsearch,Alphabetical,我正在进行Elasticsearch查询,我希望结果按姓氏字母顺序排列。我的问题是:姓氏都是西班牙语的双名,而且ES没有按照我想要的方式排序。 我希望订单是: Batres Rivera Batrín Chojoj Fion Morales Lopez Giron Martinez Castellanos Milán Casanova 这是我的疑问: { "query": { "match_all": {} }, "sort": [ { "Last Na

我正在进行Elasticsearch查询,我希望结果按姓氏字母顺序排列。我的问题是:姓氏都是西班牙语的双名,而且ES没有按照我想要的方式排序。 我希望订单是:

Batres Rivera
Batrín Chojoj
Fion Morales
Lopez Giron
Martinez Castellanos
Milán Casanova
这是我的疑问:

{
  "query": {
    "match_all": {}
  },
  "sort": [
    {
      "Last Name": {
        "order": "asc"
      }
    }
  ]
}
我得到的订单是:

Batres Rivera
Batrín Chojoj
Milán Casanova
Martinez Castellanos
Fion Morales
Lopez Giron
因此,它不是按第一个字符串排序,而是按两个字符串中的任何一个(Batres、Batrín、Cassanova、Castellanos、Fion、Giron)排序。
如果我再试试

{
    "order": "asc",
    "mode": "max"
}
然后我得到:

Batrín Chojoj
Lopez Giron
Martinez Castellanos
Milán Casanova
Fion Morales
Batres Rivera
默认情况下,所有字段都被索引,我用

curl -XGET localhost/my_index/_mapping 
我回来了

my_index: {
    my_type: {
        properties: {
            FirstName: {
                type: string
            }LastName: {
                type: string
            }MiddleName: {
                type: string
            }
            ...
        }
    }
}
有人知道如何将结果按姓氏开头字符串的字母顺序排序吗


谢谢

我们需要知道您是如何为名称编制索引的

请检查此讨论链接

这对你的案子很有帮助。这取决于映射设置。名称字段使用的分析器


需要您的映射定义来决定正确的解决方案。

问题是您的
LastName
字段已被分析,因此字符串
Batres Rivera
被索引为一个多值字段,包含两个术语:
Batres
Rivera
。但这不像一个有序数组,它更像一个“价值包”。因此,当您尝试对字段进行排序时,它会选择一个术语(最小值<代码>或最大值<代码>)并对其进行排序

您需要做的是将
LastName
存储为单个术语(
Batres Rivera
),以便进行排序,方法是将字段映射为

{ "type": "string", "index": "not_analyzed"}
显然,您不能将该字段用于搜索目的:您将无法搜索
rivera
并在该字段上进行匹配

支持搜索和排序的方法是使用多个字段:即以两种方式索引相同的值,一种用于搜索,另一种用于排序

在0.90.*中,多字段的语法为:

curl -XPUT "http://localhost:9200/my_index" -d'
{
   "mappings": {
      "my_type": {
         "properties": {
            "LastName": {
               "type": "multi_field",
               "fields": {
                  "LastName": {
                     "type": "string"
                  },
                  "raw": {
                     "type": "string",
                     "index": "not_analyzed"
                  }
               }
            }
         }
      }
   }
}'
在1.0.*中,
multi_字段
类型已被删除,现在任何核心字段类型都支持子字段,如下所示:

curl -XPUT "http://localhost:9200/my_index" -d'
{
   "mappings": {
      "my_type": {
         "properties": {
            "LastName": {
               "type": "string",
               "fields": {
                  "raw": {
                     "type": "string",
                     "index": "not_analyzed"
                  }
               }
            }
         }
      }
   }
}'
因此,您可以使用
LastName
字段进行搜索,使用
LastName.raw
字段进行排序:

curl -XGET "http://localhost:9200/my_index/my_type/_search" -d'
{
   "query": {
      "match": {
         "LastName": "rivera"
      }
   },
   "sort": "LastName.raw"
}'
特定语言排序 您还应该了解如何使用来使用西班牙语排序顺序(或排序规则)进行排序。这有点复杂,但值得使用:

curl -XPUT "http://localhost:9200/my_index" -d'
{
   "settings": {
      "analysis": {
         "analyzer": {
            "folding": {
               "type": "custom",
               "tokenizer": "icu_tokenizer",
               "filter": [
                  "icu_folding"
               ]
            },
            "es_sorting": {
               "type": "custom",
               "tokenizer": "keyword",
               "filter": [
                  "lowercase",
                  "spanish"
               ]
            }
         },
         "filter": {
            "spanish": {
               "type": "icu_collation",
               "language": "es"
            }
         }
      }
   },
   "mappings": {
      "my_type": {
         "properties": {
            "LastName": {
               "type": "string",
               "analyzer": "folding", 
               "fields": {
                  "raw": {
                     "type": "string",
                     "analyzer": "es_sorting"
                  }
               }
            }
         }
      }
   }
}'
我们创建了一个
折叠
分析器,用于
LastName
字段,它将像
穆尼奥斯河
这样的字符串分析为两个术语
穆尼奥斯河
(没有
~
)和
。因此,用户可以搜索
munoz
muñoz
,两者都将匹配

然后,我们创建
es_排序
分析器,它用西班牙语为
muñoz rivera
(小写)的正确排序顺序编制索引

搜索将以相同的方式进行:

curl -XGET "http://localhost:9200/my_index/my_type/_search" -d'
{
   "query": {
      "match": {
         "LastName": "rivera"
      }
   },
   "sort": "LastName.raw"
}'

我没有事先创建映射。嗯,我真的不知道这对我有什么帮助。我还没有使用分析仪。我必须这样才能排序吗?我也不能去任何一个网站,我不是付费客户。我可以知道你们索引了哪些领域吗?您是如何为文档编制索引的?我没有指定要为哪些字段编制索引,因此默认情况下所有字段都应编制索引。我使用curl-XGET“”进行了检查,它返回了所有字段,因此应该可以工作。好的。是否可以使用以下命令的输出更新问题:
curl-XGET'127.0.0.1:9200/my_index/\u mapping?pretty'
答案中是否缺少任何内容?如果没有,你能接受吗?对不起,我以为我已经接受了,现在就接受了。不,没有遗漏,谢谢!