我试图运行一个复杂的查询,根据有多少词匹配加权关键字字段的排名结果。问题是它不起作用,匹配更多关键字的结果比匹配更少的结果得分更低。有人知道我做错了什么吗?
以下是我的查询:
{
"from": 0,
"min_score": 5.0,
"query": {
"bool": {
"filter": [
{
"match": {
"whse": {
"query": "9999"
}
}
},
{
"bool": {
"should": [
{
"match": {
"partClass": {
"query": "Plumbing"
}
}
},
{
"match": {
"partClass": {
"query": "Miscellaneous"
}
}
}
]
}
},
{
"term": {
"isDiscontinued": {
"value": false
}
}
}
],
"should": [
{
"prefix": {
"partNo": {
"boost": 20.0,
"case_insensitive": true,
"value": "wolverine brass faucets"
}
}
},
{
"prefix": {
"partNo.keyword": {
"boost": 20.0,
"case_insensitive": true,
"value": "wolverine brass faucets"
}
}
},
{
"prefix": {
"oEM": {
"boost": 15.0,
"case_insensitive": true,
"value": "wolverine brass faucets"
}
}
},
{
"prefix": {
"oEM.keyword": {
"boost": 15.0,
"case_insensitive": true,
"value": "wolverine brass faucets"
}
}
},
{
"match": {
"keyword1": {
"boost": 15.0,
"query": "wolverine brass faucets"
}
}
},
{
"match": {
"keyword2": {
"boost": 14.0,
"query": "wolverine brass faucets"
}
}
},
{
"match": {
"keyword3": {
"boost": 13.0,
"query": "wolverine brass faucets"
}
}
},
{
"match": {
"keyword4": {
"boost": 20.0,
"query": "wolverine brass faucets"
}
}
},
{
"match": {
"keyword5": {
"boost": 11.0,
"query": "wolverine brass faucets"
}
}
},
{
"match": {
"keyword6": {
"boost": 10.0,
"query": "wolverine brass faucets"
}
}
},
{
"match": {
"keyword7": {
"boost": 9.0,
"query": "wolverine brass faucets"
}
}
},
{
"match": {
"keyword8": {
"boost": 8.0,
"query": "wolverine brass faucets"
}
}
},
{
"match": {
"keyword9": {
"boost": 7.0,
"query": "wolverine brass faucets"
}
}
},
{
"match": {
"keyword10": {
"boost": 6.0,
"query": "wolverine brass faucets"
}
}
},
{
"match": {
"keyword11": {
"boost": 5.0,
"query": "wolverine brass faucets"
}
}
},
{
"match": {
"keyword12": {
"boost": 4.0,
"query": "wolverine brass faucets"
}
}
},
{
"match": {
"description": {
"query": "wolverine brass faucets"
}
}
}
]
}
},
"size": 1000
}
字符串
这是我的Map:
{
"partinfo_20231113_172838": {
"mappings": {
"properties": {
"category": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"description": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"filterValue": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"isDiscontinued": {
"type": "boolean"
},
"keyword1": {
"type": "text",
"analyzer": "customAnalyzerSynonym"
},
"keyword10": {
"type": "text",
"analyzer": "customAnalyzerSynonym"
},
"keyword11": {
"type": "text",
"analyzer": "customAnalyzerSynonym"
},
"keyword12": {
"type": "text",
"analyzer": "customAnalyzerSynonym"
},
"keyword2": {
"type": "text",
"analyzer": "customAnalyzerSynonym"
},
"keyword3": {
"type": "text",
"analyzer": "customAnalyzerSynonym"
},
"keyword4": {
"type": "text",
"analyzer": "customAnalyzerSynonym"
},
"keyword5": {
"type": "text",
"analyzer": "customAnalyzerSynonym"
},
"keyword6": {
"type": "text",
"analyzer": "customAnalyzerSynonym"
},
"keyword7": {
"type": "text",
"analyzer": "customAnalyzerSynonym"
},
"keyword8": {
"type": "text",
"analyzer": "customAnalyzerSynonym"
},
"keyword9": {
"type": "text",
"analyzer": "customAnalyzerSynonym"
},
"keywords": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"make": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"oEM": {
"type": "text",
"analyzer": "keyword",
"index_prefixes": {
"min_chars": 3,
"max_chars": 15
}
},
"partClass": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"partNo": {
"type": "text",
"analyzer": "keyword",
"index_prefixes": {
"min_chars": 3,
"max_chars": 15
}
},
"restrictionCodes": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"salesYTD": {
"type": "integer"
},
"webURL": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"whse": {
"type": "short"
}
}
}
}
}
型
编辑:添加示例结果。请注意,得分较高的文档在测试查询中只包含3个关键字中的两个,尽管得分较低的结果在BOOSTED字段中包含第三个关键字。
{
"took" : 34,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 602,
"relation" : "eq"
},
"max_score" : 13.688185,
"hits" : [
{
"_index" : "partinfo_20231113_172838",
"_type" : "_doc",
"_id" : "T2MTy4sB8M5V6A6viSpT",
"_score" : 13.688185,
"_source" : {
"make" : "PPG",
"partNo" : "50042",
"oEM" : "50042",
"description" : "Stock-EZ Repair Kit for Wolverine Brass Faucets",
"whse" : 9999,
"category" : "Stock-EZ Kit",
"keyword1" : "Wolverine Brass",
"keyword2" : "Stock-EZ Kits",
"keyword3" : "Plumbing Kits",
"keywords" : [
"Wolverine Brass",
"Faucet Repair & Rebuild Kits"
],
"filterValue" : [
" Wolverine Brass ",
" Plastic ",
" 59 ",
" Boxed ",
" US ",
" Most popular Wolverine Brass faucets ",
" Faucet Repair Kits ",
" California Proposition 65 Warning, This product can expose you to chemicals including lead, which is known to the State of California to cause cancer and birth defects or other reproductive harm. For more information go to www.P65Warnings.ca.gov"
],
"salesYTD" : 0,
"isDiscontinued" : false,
"partClass" : "Plumbing"
}
},
{
"_index" : "partinfo_20231113_172838",
"_type" : "_doc",
"_id" : "UnIby4sB8M5V6A6vflpk",
"_score" : 13.100534,
"_source" : {
"make" : "PPG",
"partNo" : "85077",
"description" : "Wolverine Brass Large Label",
"whse" : 9999,
"keyword1" : "PlumbMaster",
"salesYTD" : 0,
"isDiscontinued" : false,
"partClass" : "Plumbing"
}
},
{
"_index" : "partinfo_20231113_172838",
"_type" : "_doc",
"_id" : "4I4qy4sB8M5V6A6voF0k",
"_score" : 13.100534,
"_source" : {
"make" : "PPG",
"partNo" : "PRM000021",
"description" : "Wolverine Brass Baseball Hat",
"whse" : 9999,
"keyword1" : "Wolverine Brass",
"salesYTD" : 0,
"isDiscontinued" : false,
"partClass" : "Plumbing"
}
},
{
"_index" : "partinfo_20231113_172838",
"_type" : "_doc",
"_id" : "91cNy4sB8M5V6A6vF3Hy",
"_score" : 12.730507,
"_source" : {
"make" : "PPG",
"partNo" : "2593201",
"oEM" : "2593201",
"description" : "Wolverine Brass 2593201 Escutcheon, Polished Brass",
"whse" : 9999,
"category" : "Escutcheon & Accessories",
"keyword1" : "Wolverine Brass",
"keyword2" : "Escutcheons & Accessories",
"keyword3" : "Tub & Showers",
"keyword4" : "Faucets",
"keywords" : [
"Wolverine Brass",
"Escutcheons & Accessories"
],
"filterValue" : [
" Wolverine Brass ",
" Brass ",
" Polished Brass ",
" US ",
" Shower Valve Trim ",
" California Proposition 65 Warning, This product can expose you to chemicals including lead, which is known to the State of California to cause cancer and birth defects or other reproductive harm. For more information go to www.P65Warnings.ca.gov"
],
"salesYTD" : 0,
"isDiscontinued" : false,
"partClass" : "Plumbing"
}
},
{
"_index" : "partinfo_20231113_172838",
"_type" : "_doc",
"_id" : "bXMcy4sB8M5V6A6vPuoW",
"_score" : 12.730507,
"_source" : {
"make" : "PPG",
"partNo" : "93781",
"oEM" : "93781",
"description" : "Wolverine Brass 93781 Brass Adapter, Chrome",
"whse" : 9999,
"category" : "Laboratory Accessories",
"keyword1" : "Wolverine Brass",
"keyword2" : "Laboratory Accessories",
"keyword3" : "General Maintenance",
"keywords" : [
"Wolverine Brass",
"Adapters"
],
"filterValue" : [
" Wolverine Brass ",
" Chrome ",
" 3/8 Inch NPT Female Base ",
" Brass ",
" US ",
" Adapaters 1 ",
" California Proposition 65 Warning, This product can expose you to chemicals including lead, which is known to the State of California to cause cancer and birth defects or other reproductive harm. For more information go to www.P65Warnings.ca.gov"
],
"salesYTD" : 0,
"isDiscontinued" : false,
"partClass" : "Plumbing"
}
},
{
"_index" : "partinfo_20231113_172838",
"_type" : "_doc",
"_id" : "sEgFy4sB8M5V6A6vdKa8",
"_score" : 12.029424,
"_source" : {
"make" : "PPG",
"partNo" : "00589728C",
"oEM" : "00589728C",
"description" : "Wolverine Brass 00589728C Cold Side Stem for Finale Rough Brass Laundry Faucets, Rough Brass",
"whse" : 9999,
"category" : "Cartridge & Stem",
"keyword1" : "Wolverine Brass",
"keyword2" : "Cartridges & Stems",
"keyword3" : "Faucet Repair Parts",
"keyword4" : "Faucets",
"keywords" : [
"Wolverine Brass",
"Cartridges & Stems"
],
"filterValue" : [
" Wolverine Brass ",
" Brass ",
" Finale ",
" US ",
" Finale™ Rough Brass Laundry Faucets ",
" Cartridges & Stems ",
" California Proposition 65 Warning, This product can expose you to chemicals including lead, which is known to the State of California to cause cancer and birth defects or other reproductive harm. For more information go to www.P65Warnings.ca.gov"
],
"salesYTD" : 0,
"isDiscontinued" : false,
"partClass" : "Plumbing"
}
},
{
"_index" : "partinfo_20231113_172838",
"_type" : "_doc",
"_id" : "s0gFy4sB8M5V6A6vdKa8",
"_score" : 12.029424,
"_source" : {
"make" : "PPG",
"partNo" : "00589729C",
"oEM" : "00589729C",
"description" : "Wolverine Brass 00589729C Hot Side Stem for Finale Rough Brass Laundry Faucets, Rough Brass",
"whse" : 9999,
"category" : "Cartridge & Stem",
"keyword1" : "Wolverine Brass",
"keyword2" : "Cartridges & Stems",
"keyword3" : "Faucet Repair Parts",
"keyword4" : "Faucets",
"keywords" : [
"Wolverine Brass",
"Cartridges & Stems"
],
"filterValue" : [
" Wolverine Brass ",
" Brass ",
" Finale ",
" US ",
" Finale™ Rough Brass Laundry Faucets ",
" Cartridges & Stems ",
" California Proposition 65 Warning, This product can expose you to chemicals including lead, which is known to the State of California to cause cancer and birth defects or other reproductive harm. For more information go to www.P65Warnings.ca.gov"
],
"salesYTD" : 0,
"isDiscontinued" : false,
"partClass" : "Plumbing"
}
},
{
"_index" : "partinfo_20231113_172838",
"_type" : "_doc",
"_id" : "mGQUy4sB8M5V6A6vFmDD",
"_score" : 12.029424,
"_source" : {
"make" : "PPG",
"partNo" : "52650W",
"oEM" : "52650W",
"description" : "Wolverine Brass 52650W Brass Washer Stem Packing & Washer for Finale Rough Brass Laundry Faucets",
"whse" : 9999,
"category" : "Gasket, O-Ring & Washer",
"keyword1" : "Wolverine Brass",
"keyword2" : "Gaskets, O-Rings & Washers",
"keyword3" : "Faucet Repair Parts",
"keyword4" : "Faucets",
"keywords" : [
"Wolverine Brass",
"Faucet Repair Parts"
],
"filterValue" : [
" Wolverine Brass ",
" Brass (Washer) ",
" Finale ",
" US ",
" Finale Rough Brass Laundry Faucets ",
" Faucet Repair parts ",
" California Proposition 65 Warning, This product can expose you to chemicals including lead, which is known to the State of California to cause cancer and birth defects or other reproductive harm. For more information go to www.P65Warnings.ca.gov"
],
"salesYTD" : 0,
"isDiscontinued" : false,
"partClass" : "Plumbing"
}
},
{
"_index" : "partinfo_20231113_172838",
"_type" : "_doc",
"_id" : "vmMTy4sB8M5V6A6v3-aX",
"_score" : 11.709076,
"_source" : {
"make" : "PPG",
"partNo" : "51102",
"oEM" : "51102",
"description" : "Wolverine Brass 51102 Stem Packing for 3/8 Stem Faucets",
"whse" : 9999,
"category" : "Gasket, O-Ring & Washer",
"keyword1" : "Wolverine Brass",
"keyword2" : "Gaskets, O-Rings & Washers",
"keyword3" : "Faucet Repair Parts",
"keyword4" : "Faucets",
"keywords" : [
"Wolverine Brass",
"Faucet Repair Parts"
],
"filterValue" : [
" Wolverine Brass ",
" US ",
" 3/8 Inch Stem Faucets ",
" Faucet Repair parts ",
" California Proposition 65 Warning, This product can expose you to chemicals including lead, which is known to the State of California to cause cancer and birth defects or other reproductive harm. For more information go to www.P65Warnings.ca.gov"
],
"salesYTD" : 0,
"isDiscontinued" : false,
"partClass" : "Plumbing"
}
},
{
"_index" : "partinfo_20231113_172838",
"_type" : "_doc",
"_id" : "6WMTy4sB8M5V6A6v3-aX",
"_score" : 11.709076,
"_source" : {
"make" : "PPG",
"partNo" : "51103W",
"oEM" : "51103W",
"description" : "Wolverine Brass 51103W Stem Packing for 13/32 Stem Faucets",
"whse" : 9999,
"category" : "Gasket, O-Ring & Washer",
"keyword1" : "Wolverine Brass",
"keyword2" : "Gaskets, O-Rings & Washers",
"keyword3" : "Faucet Repair Parts",
"keyword4" : "Faucets",
"keywords" : [
"Faucet Repair Parts",
"Wolverine Brass"
],
"filterValue" : [
" Wolverine Brass ",
" US ",
" 13/32 Inch Stem Faucets ",
" No ",
" Faucet Repair parts ",
" California Proposition 65 Warning, This product can expose you to chemicals including lead, which is known to the State of California to cause cancer and birth defects or other reproductive harm. For more information go to www.P65Warnings.ca.gov"
],
"salesYTD" : 0,
"isDiscontinued" : false,
"partClass" : "Plumbing"
}
},
{
"_index" : "partinfo_20231113_172838",
"_type" : "_doc",
"_id" : "J2cVy4sB8M5V6A6vQRiC",
"_score" : 11.709076,
"_source" : {
"make" : "PPG",
"partNo" : "53460W",
"oEM" : "53460W",
"description" : "Wolverine Brass 53460W Coupling Adapter for Chicago Faucets, 8 Center",
"whse" : 9999,
"category" : "Aerator & Adapter",
"keyword1" : "Wolverine Brass",
"keyword2" : "Aerators & Adapters",
"keyword3" : "Faucet Repair Parts",
"keyword4" : "Faucets",
"keywords" : [
"Wolverine Brass",
"Faucet Repair Parts"
],
"filterValue" : [
" Wolverine Brass ",
" US ",
" 8 Inch Centers Chicago Faucets ",
" Faucet Repair parts ",
" California Proposition 65 Warning, This product can expose you to chemicals including lead, which is known to the State of California to cause cancer and birth defects or other reproductive harm. For more information go to www.P65Warnings.ca.gov"
],
"salesYTD" : 0,
"isDiscontinued" : false,
"partClass" : "Plumbing"
}
},
{
"_index" : "partinfo_20231113_172838",
"_type" : "_doc",
"_id" : "lWcVy4sB8M5V6A6vQRiC",
"_score" : 11.709076,
"_source" : {
"make" : "PPG",
"partNo" : "53462W",
"oEM" : "53462W",
"description" : "Wolverine Brass 53462W Coupling Adapter for Fisher Faucets, 8 Center",
"whse" : 9999,
"category" : "Aerator & Adapter",
"keyword1" : "Wolverine Brass",
"keyword2" : "Aerators & Adapters",
"keyword3" : "Faucet Repair Parts",
"keyword4" : "Faucets",
"keywords" : [
"Wolverine Brass",
"Faucet Repair Parts"
],
"filterValue" : [
" Wolverine Brass ",
" US ",
" 8 Inch Centers Fisher Faucets ",
" Faucet Repair parts ",
" California Proposition 65 Warning, This product can expose you to chemicals including lead, which is known to the State of California to cause cancer and birth defects or other reproductive harm. For more information go to www.P65Warnings.ca.gov"
],
"salesYTD" : 0,
"isDiscontinued" : false,
"partClass" : "Plumbing"
}
},
{
"_index" : "partinfo_20231113_172838",
"_type" : "_doc",
"_id" : "UGcVy4sB8M5V6A6voNJW",
"_score" : 11.709076,
"_source" : {
"make" : "PPG",
"partNo" : "55729W",
"oEM" : "55729W",
"description" : "Wolverine Brass 55729W Cartridge Puller for 2 Handle WB Faucets",
"whse" : 9999,
"category" : "Cartridge & Handle Puller",
"keyword1" : "Wolverine Brass",
"keyword2" : "Cartridge & Handle Pullers",
"keyword3" : "Plumbing Tools",
"keyword4" : "Tools",
"keywords" : [
"Wolverine Brass",
"Plumbing Specialty Tools & Accessories"
],
"filterValue" : [
" Wolverine Brass ",
" US ",
" 2 Handle Wolverine Brass Faucets ",
" Plumbing Specialty Tools & Accessories ",
" California Proposition 65 Warning, This product can expose you to chemicals including lead, which is known to the State of California to cause cancer and birth defects or other reproductive harm. For more information go to www.P65Warnings.ca.gov"
],
"salesYTD" : 0,
"isDiscontinued" : false,
"partClass" : "Plumbing"
}
}
型
1条答案
按热度按时间vngu2lb81#
默认的
match
查询行为是匹配查询中的任何单词,正如docs所说:操作员
(可选,字符串)用于解释查询值中的文本的布尔逻辑。有效值为:
OR(默认)
例如,查询值capital of Hungary被解释为capital OR of OR Hungary。
和
例如,查询值capital of Hungary被解释为capital AND of AND Hungary。
https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
所以当你使用
字符串
它足以匹配任何单词。
尝试使用
型
你可能会错过一些记录,所以准备好复杂化你的查询。