我被简单的询问勒死了。我想匹配exac值-跳过所有ES分析过程,我需要等效的“哪里键=‘一些关键’”。
我的字段定义如下:
"url_key": {
"type": "text",
"copy_to": [
"search",
"spelling"
],
"analyzer": "standard"
},
我试过了
{
"query": {
"bool": {
"must": [
{
"match": {
"url_key": "SOME-URL"
}
}
]
}
},
}
返回非exac匹配
{
"query": {
"bool": {
"must": [
{
"term": {
"url_key": "SOME-URL"
}
}
]
}
}
}
返回0次点击
将字段类型更改为“关键字”将使“匹配”在这种情况下正常工作?我可以在不更改url_key字段的“类型”的情况下进行正确的查询吗?
发布于 2020-06-04 07:51:22
您必须修改才能使用关键字数据类型,因为分析了match
查询,默认情况下在text
字段上应用了standard analyzer
,这会破坏空格上的标记,等等。
当您将urls
存储在文本字段中时,https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-uaxurlemail-tokenizer.html只是为此目的构建的,这将处理边缘情况,应该使用它来存储urls
,而不是keyword
字段。
工作示例
索引设置与映射
{
"settings": {
"analysis": {
"analyzer": {
"url_analyzer": {
"type": "custom",
"tokenizer": "uax_url_email"
}
}
}
},
"mappings": {
"properties": {
"url_key": {
"type": "text",
"analyzer": "url_analyzer"
}
}
}
}
索引样本文档
{
"url_key" : "http://www.example.com"
}
搜索查询与您的查询相同
{
"query": {
"bool": {
"must": [
{
"match": {
"url_key": "http://www.example.com"
}
}
]
}
}
}
搜索结果
"hits": [
{
"_index": "url",
"_type": "_doc",
"_id": "1",
"_score": 0.2876821,
"_source": {
"url_key": "http://www.example.com"
}
}
]
https://stackoverflow.com/questions/62189385
复制相似问题