gpt4 book ai didi

elasticsearch - 为什么我的字词查询不起作用?

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

这是我的设置文件-

{
"settings": {
"mappings": {
"default": {
"properties": {
"AIRPORT_CODE": {
"type": "text"
},
"PROVINCE_NAME": {
"type": "text"
},
"AIRPORT_NAME": {
"type": "text"
},
"CITY_NAME": {
"type": "text"
},
"TYPE": {
"type": "keyword"
},
"COUNTRY_NAME": {
"type": "text"
}
}
}
}
}
}

这是我提取到索引中的2个文档-

文档-1
{
"AIRPORT_CODE": "SQA",
"PROVINCE_NAME": "California",
"AIRPORT_NAME": "Santa Ynez Airport",
"CITY_NAME": "SANTA YNEZ",
"TYPE": "AIRPORT"
}

文档-2
{
"PROVINCE_NAME": "SANTIAGO",
"CITY_NAME": "SANTIAGO",
"COUNTRY_NAME": "DOMINICAN REPUBLIC",
"TYPE": "HOTEL"
}

这是我的搜索查询-
{
"size": 4,
"timeout": "2m",
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "SQA"
}
}
],
"filter": [
{
"term": {
"TYPE": "AIRPORT"
}
}
]
}
},
"explain": false
}

“TYPE”字段已定义为关键字。但是上面的查询没有返回任何内容。如果将“类型”值从“机场”更改为“机场”(小写),我将得到结果。我究竟做错了什么?

注意#我的工作是使此查询正常工作,以便可以利用过滤器缓存(节点查询缓存)。

提前致谢!

更新-1:添加GET索引/ _映射
{
"rc-filter-cache": {
"mappings": {
"default": {
"properties": {
"AIRPORT_CODE": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"AIRPORT_NAME": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"CITY_NAME": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"COUNTRY_NAME": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"PROVINCE_NAME": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"TYPE": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"settings": {
"properties": {
"index": {
"properties": {
"analysis": {
"properties": {
"analyzer": {
"properties": {
"keylower": {
"properties": {
"tokenizer": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
}
}
},
"mappings": {
"properties": {
"default": {
"properties": {
"properties": {
"properties": {
"AIRPORT_CODE": {
"properties": {
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"AIRPORT_NAME": {
"properties": {
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"CITY_NAME": {
"properties": {
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"COUNTRY_NAME": {
"properties": {
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"PROVINCE_NAME": {
"properties": {
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"TYPE": {
"properties": {
"analyzer": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}

最佳答案

这是一种解决方法:

DELETE index
PUT index
{
"mappings": {
"default": {
"properties": {
"AIRPORT_CODE": {
"type": "text"
},
"PROVINCE_NAME": {
"type": "text"
},
"AIRPORT_NAME": {
"type": "text"
},
"CITY_NAME": {
"type": "text"
},
"TYPE": {
"type": "keyword"
},
"COUNTRY_NAME": {
"type": "text"
}
}
}
}
}
PUT index/default/1
{
"AIRPORT_CODE": "SQA",
"PROVINCE_NAME": "California",
"AIRPORT_NAME": "Santa Ynez Airport",
"CITY_NAME": "SANTA YNEZ",
"TYPE": "AIRPORT"
}
PUT index/default/2
{
"PROVINCE_NAME": "SANTIAGO",
"CITY_NAME": "SANTIAGO",
"COUNTRY_NAME": "DOMINICAN REPUBLIC",
"TYPE": "HOTEL"
}
GET index/_search
{
"query": {
"bool": {
"filter": [
{
"term": {
"TYPE": "AIRPORT"
}
}
]
}
}
}

关于elasticsearch - 为什么我的字词查询不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49415360/

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