gpt4 book ai didi

sorting - 内部查询中单个查询的 Elasticsearch 排序结果

转载 作者:行者123 更新时间:2023-12-03 02:28:44 25 4
gpt4 key购买 nike

我有一个Elastic Search服务器设置,用于存储要用于公司搜索的公司名称,其工作方式是:

在公司名称中,空格和点将被删除并存储在ES中的trimmedcompanyname字段中,

{
"companyName" : "RECKON INFOSYSTEM PRIVATE LIMITED",
"trimmedCompanyName" : "reckoninfosystemprivatelimited",
"id" : "1079"
}

现在,当搜索进入我的服务器时,我删除了空格和点,然后向ES服务器发出请求。查询格式的ES请求为:
GET /_search
{
"from": 0,"size":1000,
"query": {
"bool": {
"should": [
{
"wildcard": {
"trimmedCompanyName.keyword": {
"value": "infosys*"
}
}
},
{
"wildcard": {
"trimmedCompanyName.keyword": {
"value": "*infosys*"
}
}
}
]
}
}
}

现在这给出了结果
[
{
"_source" : {
"companyName" : "INFOSYS LIMITED",
"trimmedCompanyName" : "infosyslimited"
}
,
{
"_source" : {
"companyName" : "INFOSYSTEM BPO LIMITED",
"trimmedCompanyName" : "infosysbpolimited"
}
},
{
"_source" : {
"companyName" : "INFOSYS ASIC SYSTEMS",
"trimmedCompanyName" : "infosysasicsystems"
}
},
{
"_source" : {
"companyName" : "SUMEDH INFOSYSTEMS PRIVATE LIMITED",
"trimmedCompanyName" : "sumedhinfosystemsprivatelimited"
}
},
{
"_source" : {
"companyName" : "ASSURE INFOSYSTEMS PRIVATE LIMITED",
"trimmedCompanyName" : "assureinfosystemsprivatelimited"
}
},
{
"_source" : {
"companyName" : "IMBIBE INFOSYSTEM PRIVATE LIMITED",
"trimmedCompanyName" : "imbibeinfosystemprivatelimited"
}
},
{
"_source" : {
"companyName" : "GOOFY INFOSYSTEM PRIVATE LIMITED",
"trimmedCompanyName" : "goofyinfosystemprivatelimited"
}
},
{
"_source" : {
"companyName" : "DHRUV INFOSYSTEMS PRIVATE LIMITED",
"trimmedCompanyName" : "dhruvinfosystemsprivatelimited"
}
}
]

但是我想要结果
[
{
"_source" : {
"companyName" : "INFOSYS ASIC SYSTEMS",
"trimmedCompanyName" : "infosysasicsystems"
}
},
{
"_source" : {
"companyName" : "INFOSYSTEM BPO LIMITED",
"trimmedCompanyName" : "infosysbpolimited"
}
},
{
"_source" : {
"companyName" : "INFOSYS LIMITED",
"trimmedCompanyName" : "infosyslimited"
}
,
{
"_source" : {
"companyName" : "ASSURE INFOSYSTEMS PRIVATE LIMITED",
"trimmedCompanyName" : "assureinfosystemsprivatelimited"
}
},
{
"_source" : {
"companyName" : "DHRUV INFOSYSTEMS PRIVATE LIMITED",
"trimmedCompanyName" : "dhruvinfosystemsprivatelimited"
}
},
{
"_source" : {
"companyName" : "GOOFY INFOSYSTEM PRIVATE LIMITED",
"trimmedCompanyName" : "goofyinfosystemprivatelimited"
}
},
{
"_source" : {
"companyName" : "IMBIBE INFOSYSTEM PRIVATE LIMITED",
"trimmedCompanyName" : "imbibeinfosystemprivatelimited"
}
},
{
"_source" : {
"companyName" : "SUMEDH INFOSYSTEMS PRIVATE LIMITED",
"trimmedCompanyName" : "sumedhinfosystemsprivatelimited"
}
}
]

即,结果是,各个通配符查询的o / p必须在它们之间进行排序,但是第一个通配符查询的o / p应该先于第二个通配符查询的o / p。有人可以帮我吗?

最佳答案

我得到了解决方案,对搜索结果以及trimmedcompanyname进行了排序。我的最终查询是:

GET /_search
{
"from": 0,"size":1000,
"query": {
"bool": {
"should": [
{
"wildcard": {
"trimmedCompanyName.keyword": {
"value": "infosys*"
}
}
},
{
"wildcard": {
"trimmedCompanyName.keyword": {
"value": "*infosys*"
}
}
}
]
}
},
"sort": [
{
"_score": {
"order": "desc"
}
},
{
"trimmedCompanyName.keyword": {"order": "asc"}
}
]
}

希望能帮助到你!

关于sorting - 内部查询中单个查询的 Elasticsearch 排序结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60467698/

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