现在,我知道关键字不应该包含非结构化文本,但是我们可以说,出于某种原因,这样的文本被写入关键字字段 . 当使用匹配或术语查询搜索此类文档时,找不到该文档,但是当使用query_string搜索时,通过部分匹配(内部关键字中的“术语”)找到该文档 . 我不明白当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!"
}
}
]
}
1 回答
当您在弹性上执行query_string查询时,如下所示
这实际上是在_all字段上进行搜索,如果你没有提到用弹性标准分析仪进行分析 .
如果您在查询中指定字段,如下所示,您将无法获得关键字字段的记录 .