【发布时间】:2014-08-27 08:31:24
【问题描述】:
我有一些想要使用的 Twitter 数据。我希望能够搜索一个名字。在尝试生成“name”和“_id”的 ngram 时,我遇到了一些麻烦。
首先,我创建了分析器:
curl -XPUT 'localhost:9200/twitter_users' -d '
{
"settings": {
"analysis": {
"analyzer": {
"str_search_analyzer": {
"tokenizer": "keyword",
"filter": [
"lowercase"
]
},
"str_index_analyzer": {
"tokenizer": "keyword",
"filter": [
"lowercase",
"ngram"
]
}
},
"filter": {
"ngram": {
"type": "ngram",
"min_gram": 3,
"max_gram": 20
}
}
}
}
}'
然后我定义了我的映射:
curl -XPUT 'http://localhost:9200/twitter_users/users/_mapping' -d '
{
"users": {
"type" : "object",
"properties": {
"_id": {
"type": "string",
"copy_to": "id"
},
"id": {
"type": "string",
"search_analyzer": "str_search_analyzer",
"index_analyzer": "str_index_analyzer",
"index": "analyzed"
},
"name": {
"type": "multi_field",
"fields": {
"name": {
"type": "string",
"index": "not_analyzed"
},
"ngrams": {
"type": "string",
"search_analyzer": "str_search_analyzer",
"index_analyzer": "str_index_analyzer",
"index": "analyzed"
}
}
}
}
}
}'
并插入一些测试数据:
curl -XPUT "localhost:9200/twitter_users/users/johndoe" -d '{
"_id" : "johndoe",
"name" : "John Doe"
}'
curl -XPUT "localhost:9200/twitter_users/users/janedoe" -d '{
"_id" : "janedoe",
"name" : "Jane Doe"
}'
按名称查询可以得到预期的结果:
curl -XPOST "http://localhost:9200/twitter_users/users/_search" -d '{
"query": {
"match": {
"name.ngrams": "doe"
}
}
}'
但是查询 id 没有结果:
curl -XPOST "http://localhost:9200/twitter_users/users/_search" -d '{
"query": {
"match": {
"id": "doe"
}
}
}'
我还测试了使 _id 成为一个多字段,就像我对 name 所做的那样。但这也没有用。
_id 的行为是否与其他字段不同?还是我在这里做错了什么?
编辑:使用 elasticsearch v1.1.2 并使用 River 插件从 mongodb 中提取数据。
感谢您的帮助
米尔科
【问题讨论】:
-
我在这里遇到了同样的问题.. 尝试将分析器添加到 _id 字段。你有没有解决这个问题?
-
_id字段在 elasticsearch 中不再可配置,请检查 this
标签: mongodb elasticsearch n-gram elasticsearch-mongo-river