ElasticSearch找不到字符串字段中存在的确切值 [英] ElasticSearch cannot find an exact value that exists in a string field
问题描述
当我做一个空查询来列出一些结果时,我看到的值在那里。例如:
When I do an empty query to list some results, I see the values are there. Ex:
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 3024,
"max_score": 1.0,
"hits": [{
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt5-j6uVuoyTMhX204",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail1029.png"
}
}, {
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt5-mTuVuoyTMhX205",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail1321.png"
}
}, {
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt5-xkuVuoyTMhX209",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail2567.png"
}
}, {
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt5zr8uVuoyTMhX20F",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail2122.png"
}
}, {
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt5z23uVuoyTMhX20L",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail1823.png"
}
}, {
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt5-53uVuoyTMhX21A",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail1616.png"
}
}, {
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt5_AXuVuoyTMhX21C",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail3002.png"
}
}, {
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt5_j3uVuoyTMhX21U",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail3039.png"
}
}, {
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt5_yQuVuoyTMhX21d",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail1136.png"
}
}, {
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt5zbquVuoyTMhX20C",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail166.png"
}
}, {
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt5zfsuVuoyTMhX20E",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail2767.png"
}
}, {
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt59jQuVuoyTMhX20p",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail2852.png"
}
}, {
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt5_PpuVuoyTMhX21J",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail1392.png"
}
}, {
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt58YguVuoyTMhX20N",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail603.png"
}
}, {
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt5_38uVuoyTMhX21h",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail416.png"
}
}, {
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt5-JFuVuoyTMhX20y",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail896.png"
}
}, {
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt6B1NuVuoyTMhX22i",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail846.png"
}
}, {
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt6B3vuVuoyTMhX22k",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail1214.png"
}
}, {
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt6B90uVuoyTMhX22o",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail1536.png"
}
}, {
"_index": "geotiff_test",
"_type": "geometa",
"_id": "AVtt6COkuVuoyTMhX22y",
"_score": 1.0,
"_source": {
"thumbnail": "thumbnail246.png"
}
}]
}
}
当我运行这样的查询,它r没有任何东西:
Yet when I run a query like this, it returns nothing:
curl -X POST http://localhost:9200/geotiff_test/geometa/_search -d '{
"query": {
"term": {
"thumbnail": "thumbnail1536.png"
}
}
}'
这是结果:
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
如果这是Solr所有我想做的是运行这个简单的查询: thumbnail:thumbnail1536.png
If this were Solr, all I want to do is run this simple query: thumbnail:"thumbnail1536.png"
有人可以告诉我在这里出了什么问题?
Can someone tell me what is going wrong here?
推荐答案
确切的术语不匹配,因为您的文档字段 thumbnail
用
标准
分析仪进行分析并存储它作为 thumbnail1536
和 png
。
Exact term is not matching because your document field thumbnail
got analyzed with standard
analyzer and stored it as thumbnail1536
and png
.
在弹性搜索对文本
(全文)和关键字
(确切)的不同查询-term 强>)。你写的是后一类。
In Elasticsearch there are different queries for text
(full-text) and keyword
(exact-term). The one you written comes under latter category.
如果您运行以下全文
查询,您将获得所需的结果:
If you run following full-text
query you will get desired results:
curl -X POST http://localhost:9200/geotiff_test/geometa/_search -d '{
"query": {
"match": {
"thumbnail": "thumbnail1536.png"
}
}
}'
但是,当您尝试使用术语$ c $搜索
确切项
c>查询是首选的。
But as you are trying to search for exact-term
using term
queries are preferred.
curl -X POST http://localhost:9200/geotiff_test/geometa/_search -d '{
"query": {
"term": {
"thumbnail.keyword": "thumbnail1536.png"
}
}
}'
注意:这里 .keyword
是关键字
版本的缩略图
字段。
Note: Here .keyword
is keyword
version of thumbnail
field.
尽管两者都产生相同的结果,上述查询更多高于前者。
Although both yield same results, the above query is more efficient than former one.
这篇关于ElasticSearch找不到字符串字段中存在的确切值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!