gpt4 book ai didi

database - 如何使用查询匹配AND而不是逗号?

转载 作者:行者123 更新时间:2023-12-03 00:45:17 25 4
gpt4 key购买 nike

我有3列“为什么,目标,费率,相似”。这是一种推荐系统。目标是“A酒店”,类似于“B酒店,C酒店”,这是原因。如果“为什么”列包含“Antalya,Kum Plaj”,当您查看下图时,我的结果必须像“Antalya AND Kum Plaj”一样包含“Antalya,Kum Plaj”,您可以看到“Antalya,Kum Plaj”作为“安塔利亚或库姆普拉”。
我尝试了2个查询,但它们均无法正常工作。
我的第一个查询:

    {
"query": {
"bool": {
"must": [
{
"range": {
"rate": {
"gte": 0.7,
"lte": 1,
"boost": 2.0
}
}
},
{
"term": {
"target.keyword": "Robinson Club Nobilis"
}
},
{
"match": {
"why": "Antalya,Kum Plaj"
}
}
]
}

}
}
第二个查询:
    POST /hotelsimilaritydeneme*/_search
{
"query":{
"multi_match" : {
"query": "(Kum Plaj AND Antalya) and Not why.keyword : '' and target.keyword :'Design Plus Seya Beach' and rate >= 0.6",
"fields": [ "why","target","rate"]
}
}
}

我并不感到困惑,但是结果应该包括“Kum plaj,Antalya”。但是某些结果只有“kum plaj”总和结果“Antalya”,当然还有另一个酒店特色。但是“Kum Plaj,Antalya”应该工作为“Kum Plaj AND Antalya”,而不是“Kum Plaj Or Antalya”
这是我的映射:
{
"mapping": {
"object": {
"properties": {
"rate": {
"type": "float"
},
"similarTo": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"target": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"why": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
我的样本数据:
{
"took": 98,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 17,
"max_score": 10.760553,
"hits": [
{
"_index": "xxx-2020",
"_type": "object",
"_id": "nuy9cnMBwlYcZ3X2cH4o",
"_score": 10.760553,
"_source": {
"target": "Robinson Club Nobilis",
"similarTo": "Crystal Waterworld Resort & Spa",
"rate": 0.75,
"why": "Diyet Büfesi,Kum Plaj,Antalya"
}
},
{
"_index": "xxx-2020",
"_type": "object",
"_id": "yuy9cnMBwlYcZ3X2cH4o",
"_score": 10.760553,
"_source": {
"target": "Robinson Club Nobilis",
"similarTo": "Crystal Sunset Luxury Resort & Spa",
"rate": 0.75,
"why": "Diyet Büfesi,Kum Plaj,Antalya"
}
}]
}
}

最佳答案

它按照映射工作。因为text使用standard分析器。因此,您的条款将被标记为

{
"tokens": [
{
"token": "kum",
"start_offset": 0,
"end_offset": 3,
"type": "<ALPHANUM>",
"position": 0
},
{
"token": "plaj",
"start_offset": 4,
"end_offset": 8,
"type": "<ALPHANUM>",
"position": 1
},
{
"token": "antalya",
"start_offset": 9,
"end_offset": 16,
"type": "<ALPHANUM>",
"position": 2
}
]
}
因此,仅 Antalya文档是结果的一部分。
为避免这种情况,您需要更改映射。
我建议您使用逗号分隔的 patternTokenizerstandard filter
要实现相同的映射:
{
"query":{
"query_string":{
"fields":["why"],
"query": "Kum Plaj, Antalya",
"default_operator":"and"
}
}
}
文件-输出:
"hits": [
{
"_index": "similar",
"_type": "_doc",
"_id": "aafzvXMBoP4Sw8kfTdzk",
"_score": 0.7161402,
"_source": {
"target": "Robinson Club Nobilis",
"similarTo": "Crystal Waterworld Resort & Spa",
"rate": 0.75,
"why": "Diyet Büfesi,Kum Plaj,Antalya"
}
},
{
"_index": "similar",
"_type": "_doc",
"_id": "aqfzvXMBoP4Sw8kfctxi",
"_score": 0.7161402,
"_source": {
"target": "Robinson Club Nobilis",
"similarTo": "Crystal Sunset Luxury Resort & Spa",
"rate": 0.75,
"why": "Diyet Büfesi,Kum Plaj,Antalya"
}
}
]
输入文档:
"hits": [
{
"_index": "similar",
"_type": "_doc",
"_id": "aafzvXMBoP4Sw8kfTdzk",
"_score": 1.0,
"_source": {
"target": "Robinson Club Nobilis",
"similarTo": "Crystal Waterworld Resort & Spa",
"rate": 0.75,
"why": "Diyet Büfesi,Kum Plaj,Antalya"
}
},
{
"_index": "similar",
"_type": "_doc",
"_id": "aqfzvXMBoP4Sw8kfctxi",
"_score": 1.0,
"_source": {
"target": "Robinson Club Nobilis",
"similarTo": "Crystal Sunset Luxury Resort & Spa",
"rate": 0.75,
"why": "Diyet Büfesi,Kum Plaj,Antalya"
}
},
{
"_index": "similar",
"_type": "_doc",
"_id": "a6f1vXMBoP4Sw8kfrNyB",
"_score": 1.0,
"_source": {
"target": "Robinson Club Nobilis",
"similarTo": "Crystal Sunset Luxury Resort & Spa",
"rate": 0.75,
"why": "Diyet Büfesi,Kum Plaj"
}
}
]

关于database - 如何使用查询匹配AND而不是逗号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63248910/

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