【发布时间】:2017-07-21 09:17:16
【问题描述】:
现在,我知道关键字不应该包含非结构化文本,但假设出于某种原因,恰好将此类文本写入关键字字段。 使用 match 或 term 查询搜索此类文档时,找不到文档,但使用 query_string 搜索时,通过部分匹配(关键字内部的“term”)找到文档。当 Elasticsearch 的文档明确指出关键字按原样进行反向索引时,我不明白这是怎么可能的,没有术语标记化。 例子: 我的索引映射:
PUT my_index
{
"mappings": {
"my_type": {
"properties": {
"full_text": {
"type": "text"
},
"exact_value": {
"type": "keyword"
}
}
}
}
}
然后我把一个文件放进去:
PUT my_index/my_type/2
{
"full_text": "full text search",
"exact_value": "i want to find this trololo!"
}
想象一下当我得到一个按关键字词而不是完全匹配的文档时我的惊讶:
GET my_index/my_type/_search
{
"query": {
"match": {
"exact_value": "trololo"
}
}
}
- 没有结果;
GET my_index/my_type/_search
{
"query": {
"term": {
"exact_value": "trololo"
}
}
}
- 没有结果;
POST my_index/_search
{"query":{"query_string":{"query":"trololo"}}}
- 我的文档被退回(!):
"hits": {
"total": 1,
"max_score": 0.27233246,
"hits": [
{
"_index": "my_index",
"_type": "my_type",
"_id": "2",
"_score": 0.27233246,
"_source": {
"full_text": "full text search",
"exact_value": "i want to find this trololo!"
}
}
]
}
【问题讨论】:
标签: elasticsearch