AWS ElasticSearch-匹配查询不起作用 [英] AWS ElasticSearch - Match Query Not Working

查看:148
本文介绍了AWS ElasticSearch-匹配查询不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过AWS托管的ElasticSearch服务(版本7.4.2)部署了一个弹性搜索实例,但无法使匹配"查询正常工作.我正在研究示例航班数据集并运行以下查询:

I have deployed an elastic search instance through AWS` managed ElasticSearch service (version 7.4.2) and having trouble getting "match" queries working. I am playing around with the sample flights dataset and running the following query:

数据:

[
    {
        "FlightNum": "HX0WBLI",
        "DestCountry": "IT",
        "OriginWeather": "Damaging Wind",
        "OriginCityName": "Chitose / Tomakomai",
        "AvgTicketPrice": 988.8975638746068,
        "DistanceMiles": 5650.511340218511,
        "FlightDelay": false,
        "DestWeather": "Sunny",
        "Dest": "Verona Villafranca Airport"
    },
    {
        "FlightNum": "VG7H7U4",
        "DestCountry": "IT",
        "OriginWeather": "Cloudy",
        "OriginCityName": "Milan",
        "AvgTicketPrice": 223.66801608639728,
        "DistanceMiles": 78.45850223819446,
        "FlightDelay": false,
        "DestWeather": "Sunny",
        "Dest": "Verona Villafranca Airport"
    },
    {
        "FlightNum": "B3CVVO3",
        "DestCountry": "IT",
        "OriginWeather": "Cloudy",
        "OriginCityName": "Sydney",
        "AvgTicketPrice": 360.41688271717148,
        "DistanceMiles": 10207.122317757072,
        "FlightDelay": false,
        "DestWeather": "Rain",
        "Dest": "Verona Villafranca Airport"
    }
]

查询:

POST kibana_sample_data_flights/_search
{
   "query": {
       "match":{
           "Dest": "Verona"
       }
    }
}

我知道有些项目应该部分匹配,但是我得到了一个空结果集.指定完整值维罗纳·维拉弗兰卡机场"将产生一些结果.是否需要启用某些功能才能使上面的查询正常工作?

I know there are items with that should partially match but I get an empty result set back. Specifying the full value "Verona Villafranca Airport" yields some results. Is something needs to be enabled to get the query above working?

对于本地实例(通过docker部署),相同的查询也可以正常工作.

Also the same query works as expected against a local instance (deployed through docker).

感谢您的帮助!

推荐答案

由于您没有提供映射并查看您的问题,因此似乎在映射中,Dest字段被定义为keyword,而不是分析.因此存储Verona Villafranca Airport将按原样存储.

As you have not provided your mapping and looking at your question, it seems in your mapping, Dest field is defined as keyword which isn't analyzed. hence storing Verona Villafranca Airport would be stored as it is.

使用匹配时被分析的查询表示它使用与索引字段相同的分析器,在这种情况下为keyword,因此搜索Verona Villafranca Airport会返回结果,因为此令牌存在于反向索引中,同时进行搜索Verona不会匹配任何令牌,因此您不会得到任何结果.

When you use the match query which is analyzed means it uses the same analyzer used to index the field, which would be keyword in this case, hence searching for Verona Villafranca Airport returns the result as this token present in the inverted index, while searching for Verona will not match any token, hence you don't get any result.

解决方案:如果您要进行不区分大小写的搜索,并且要在Veronaairport上进行搜索,则需要将此Dest字段定义为text,并且Elasticsearch默认使用standard分析器会自动小写并在空白处分割文本,这将启用上述搜索条件.

Solution: if you want the case insensitive search and want to search on Verona or airport, then you need to define this Dest field as text and Elasticsearch uses the standard analyzer by default which would automatically lowercase and split the text on whitespace, which would enable above search criteria.

随后,您可以使用相同的match查询,该查询将按照文档中的说明进行工作.

And later on you can use the same match query, which you are using and it would work as explained in docs.

从文档中查询match的注意事项

Note on match query from doc

返回与提供的文本,数字,日期或布尔值匹配的文档 价值.匹配之前对提供的文本进行分析.

Returns documents that match a provided text, number, date or boolean value. The provided text is analyzed before matching.

标准分析仪生成的令牌

POST /_analyze
{
    "text" : "Verona Villafranca Airport",
    "analyzer" : "standard"
}

{
    "tokens": [
        {
            "token": "verona",
            "start_offset": 0,
            "end_offset": 6,
            "type": "<ALPHANUM>",
            "position": 0
        },
        {
            "token": "villafranca",
            "start_offset": 7,
            "end_offset": 18,
            "type": "<ALPHANUM>",
            "position": 1
        },
        {
            "token": "airport",
            "start_offset": 19,
            "end_offset": 26,
            "type": "<ALPHANUM>",
            "position": 2
        }
    ]
}

由关键字生成的令牌

POST /_analyze

{
    "text" : "Verona Villafranca Airport",
    "analyzer" : "keyword"
}

{
    "tokens": [
        {
            "token": "Verona Villafranca Airport",
            "start_offset": 0,
            "end_offset": 26,
            "type": "word",
            "position": 0
        }
    ]
}

这篇关于AWS ElasticSearch-匹配查询不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆