我有一个名为ID的字段,看起来像:
ventures.something.123
是映射:
{
"id":{
"fields":{
"keyword":{
"ignore_above":256,
"type":"keyword"
}
},
"type":"text"
}
}
我的理解是,关键字仅允许确切匹配 - 这是我想要的。
但是,分析仪告诉我它已被标记:
> http http://localhost:9200/my_index/_analyze field=id text='ventures.house.1137'
{
"tokens": [
{
"end_offset": 14,
"position": 0,
"start_offset": 0,
"token": "ventures.house",
"type": "<ALPHANUM>"
},
{
"end_offset": 19,
"position": 1,
"start_offset": 15,
"token": "1137",
"type": "<NUM>"
}
]
}
...搜索ID返回确实以ventures.house
开头的所有ID。
为什么这是以及我该如何达到确切的匹配?
是ES 5.2。
来自https://www.elastic.co/guide/guide/en/elasticsearch/guide/guide/current/mapping-intro.html#_index_2
not_analyzed: 索引此字段,因此可以搜索,但请完全按照指定的方式索引值。不要分析它。
{
"tag": {
"type": "string",
"index": "not_analyzed"
}
}
我误读了映射,看来我的 elasticsearch-dsl
库不是直接创建关键字,而是将其添加为子字段。
您是否尝试过将字段'ID'定义为关键字?
在这种情况下,它不会被分析,而是按原样存储。当我正确理解您的问题时,这就是您想要的。
{
"id":{
"type":"keyword"
}
}
请参阅https://www.elastic.co/guide/en/elasticsearch/reference/reference/current/keyword.html
我希望这有所帮助。基督徒