zip_code 上的 Elasticsearch 查询失败
Elasticsearch query on zip_code failed
我在 elasticsearch 上有一个我无法解释的奇怪行为。
当我这样做时:
POST /ad_search/_search
{
"query": {
"match": {
"city_code": "2A247"
}
}
}
我有多个结果。但是当我这样做时(此代码由图书馆生成):
POST /ad_search/_search
{
"from":0,
"query": {
"bool": {
"must":[
{"term":{"city_code":"2A247"}}
]
}
}
}
我没有结果。
当我在所有其他 zip_code 上搜索时只使用 71459 这样的数字。这两个查询都运行良好并给出相同的结果。
我正在考虑映射问题,但似乎没问题:
GET /ad_search/_mapping
{
"ad_search" : {
"mappings" : {
"properties" : {
"city_code" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
有人有解锁我的想法吗?
谢谢
因为city_code
是文本类型,所以被分析,所以索引的是2a247
(小写)。
因此您可以使用 term
查询来查询 city_code.keyword
,这会进行完全匹配
POST /ad_search/_search
{
"from":0,
"query": {
"bool": {
"must":[
{"term":{"city_code.keyword":"2A247"}}
]
}
}
}
或在 city_code
字段上进行匹配查询:
POST /ad_search/_search
{
"from":0,
"query": {
"bool": {
"must":[
{"match":{"city_code":"2A247"}}
]
}
}
}
我在 elasticsearch 上有一个我无法解释的奇怪行为。
当我这样做时:
POST /ad_search/_search
{
"query": {
"match": {
"city_code": "2A247"
}
}
}
我有多个结果。但是当我这样做时(此代码由图书馆生成):
POST /ad_search/_search
{
"from":0,
"query": {
"bool": {
"must":[
{"term":{"city_code":"2A247"}}
]
}
}
}
我没有结果。
当我在所有其他 zip_code 上搜索时只使用 71459 这样的数字。这两个查询都运行良好并给出相同的结果。
我正在考虑映射问题,但似乎没问题:
GET /ad_search/_mapping
{
"ad_search" : {
"mappings" : {
"properties" : {
"city_code" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
有人有解锁我的想法吗?
谢谢
因为city_code
是文本类型,所以被分析,所以索引的是2a247
(小写)。
因此您可以使用 term
查询来查询 city_code.keyword
,这会进行完全匹配
POST /ad_search/_search
{
"from":0,
"query": {
"bool": {
"must":[
{"term":{"city_code.keyword":"2A247"}}
]
}
}
}
或在 city_code
字段上进行匹配查询:
POST /ad_search/_search
{
"from":0,
"query": {
"bool": {
"must":[
{"match":{"city_code":"2A247"}}
]
}
}
}