我有以下映射:
{
"events": {
"mappings": {
"event": {
"Type of Event": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
并且下面的数据在索引里面
{
"Type of Event": "Orientation Session"
},
{
"Type of Event": "Orientation Tutorial"
}
我试图只匹配那些
Type of Event == "Orientation Session"
。我正在尝试以下查询:
{
"query": {
"term": {
"Type of Event.keyword": "Orientation Session"
}
}
}
但它不匹配任何东西。但是,如果字符串中没有空格,它将起作用。我不能在这里使用
match
查询,因为它会匹配两个事件。我究竟做错了什么?我已经看到了很多关于术语查询中的空格的讨论,但是没有关于使用
keyword
的讨论。它们都是特定于elasticsearch 2.0的。
最佳答案
问题是您的映射错误,缺少了properties
关键字。
如果尝试使用给定的映射来创建索引,则应该得到以下错误:
unknown setting [index.events.mappings.event.Type of Event.fields.keyword.ignore_above] please check that any required plugins are installed, or check the breaking changes documentation for removed settings
因此,您需要改用以下映射,它将起作用:
{
"mappings": {
"event": {
"properties": { <--- this was missing
"Type of Event": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
关于elasticsearch - 关键字查询中带空格的Elasticsearch关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45004769/