我正在使用elasticsearch
. 我看到每个文档都有元字段_id
。我想使用此元字段搜索文档,因为我没有任何其他字段作为文档中的唯一字段。But_id
是一个字符串,并且可以包含无法搜索的破折号,除非我们将字段映射添加为type :keyword
. 但这是可能的,正如这里提到的。所以现在我正在考虑newField
在文档中添加另一个字段并使其与_id
. 一种方法是:首先创建文档并分配_id
给该字段并再次保存文档。但这将有 2 个不太好的连接。所以我想newField
在创建文档本身时找到一些解决方案。甚至可能吗?
问问题
983 次
2 回答
0
您可以搜索包含破折号的文档:
PUT my_index/tweet/testwith-
{
"fullname" : "Jane Doe",
"text" : "The twitter test!"
}
我们刚刚创建了一个 id 中带有破折号的文档
GET my_index/tweet/_search
{
"query": {
"terms": {
"_id": [
"testwith-"
]
}
}
}
我们搜索具有以下 id 的文档:testwith-
{
"took": 9,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "my_index",
"_type": "tweet",
"_id": "testwith-",
"_score": 1,
"_source": {
"fullname": "Jane Doe",
"text": "The twitter test!"
}
}
]
}
}
我们找到了。我们可以搜索包含 - 的文档。
于 2017-08-29T14:33:05.287 回答
0
您还可以在使用摄取管道将 id 存储在附加字段中时使用集合处理器,请参阅https://www.elastic.co/guide/en/elasticsearch/reference/5.5/accessing-data-in-pipelines。 html和https://www.elastic.co/guide/en/elasticsearch/reference/5.5/set-processor.html
于 2017-08-29T20:27:11.617 回答