gpt4 book ai didi

elasticsearch - 如何指定 ElasticSearch copy_to 顺序?

转载 作者:行者123 更新时间:2023-11-29 02:46:51 52 4
gpt4 key购买 nike

ElasticSearch 能够将值复制到其他字段(在索引时),使您能够像搜索一个字段一样搜索多个字段 ( Core Types: copy_to )。

但是,似乎没有任何方法可以指定复制这些值的顺序。这在短语匹配时可能很重要:

curl -XDELETE 'http://10.11.12.13:9200/helloworld'
curl -XPUT 'http://10.11.12.13:9200/helloworld'
# copy_to is ordered alphabetically!
curl -XPUT 'http://10.11.12.13:9200/helloworld/_mapping/people' -d '
{
"people": {
"properties": {
"last_name": {
"type": "string",
"copy_to": "full_name"
},
"first_name": {
"type": "string",
"copy_to": "full_name"
},
"state": {
"type": "string"
},
"city": {
"type": "string"
},
"full_name": {
"type": "string"
}
}
}
}
'

curl -X POST "10.11.12.13:9200/helloworld/people/dork" -d '{"first_name": "Jim", "last_name": "Bob", "state": "California", "city": "San Jose"}'
curl -X POST "10.11.12.13:9200/helloworld/people/face" -d '{"first_name": "Bob", "last_name": "Jim", "state": "California", "city": "San Jose"}'


curl "http://10.11.12.13:9200/helloworld/people/_search" -d '
{
"query": {
"match_phrase": {
"full_name": {
"query": "Jim Bob"
}
}
}
}
'

只返回“Jim Bob”;这些字段似乎是按字段名称字母顺序复制的。

我如何切换 copy_to 订单,以便返回“Bob Jim”人?

最佳答案

这可以通过注册一个 transform script 来更确定地控制。在你的映射中。

像这样:

"transform" : [
{"script": "ctx._source['full_name'] = [ctx._source['first_name'] + " " + ctx._source['last_name'], ctx._source['last_name'] + " " + ctx._source['first_name']]"}
]

此外,转换脚本可以是“本地”的,即 java 代码,通过使您的自定义类在 elasticsearch 类路径中可用并通过设置注册为本地脚本,使集群中的所有节点都可用:

script.native.<name>.type=<fully.qualified.class.name>

在这种情况下,在您的映射中,您将像这样将 native 脚本注册为转换:

"transform" : [
{
"script" : "<name>",
"params" : {
"param1": "val1",
"param2": "val2"
},
"lang": "native"
}
],

关于elasticsearch - 如何指定 ElasticSearch copy_to 顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29534337/

52 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com