[英]How to index the MongoDB “id_” field with Elasticsearch?
I'm using ElasticSearch with MongoDB and want to search for ObjectIDs in my Elasticsearch Index. 我正在将ElasticSearch与MongoDB结合使用,并想在我的Elasticsearch索引中搜索ObjectID。
My MongoDB contains entries like: 我的MongoDB包含如下条目:
{ "_id" : ObjectId("54ca06664ceb6693d37de155"), "blabla" : "xxxyyy"}
I tried to create a custom mapping for example: 我尝试创建一个自定义映射,例如:
curl -XPOST "http://localhost:9200/myIndex/myType/_mapping" -d'
{
"myType":{
"properties":{
"_all": {
"enabled": false
},
"_id": {
"type": "string",
"store": true,
"index": "analyzed"
},
"blabla": {
"type": "string",
"store": true,
"index": "analyzed"
}
}
}' }'
but when I want to check my mappings with 但是当我想检查我的映射时
curl -XGET 'http://localhost:9200/_all/_mapping'
I can't see the _id mapping. 我看不到_id映射。 Searching for "54ca06664ceb6693d37de155" also does not return any results.
搜索“ 54ca06664ceb6693d37de155”也不会返回任何结果。
What's wrong? 怎么了?
_id field is default primary key in Elasticsearch like mongoDB.Though you dont find mapping for _id field, you can search for _id field using below query. _id字段是像mongoDB这样的Elasticsearch中的默认主键。尽管您没有找到_id字段的映射,但是可以使用以下查询搜索_id字段。 for more info refer this link.
有关更多信息, 请参考此链接。
You can find _id field in returns documents: 您可以在退货凭证中找到_id字段:
{
"_index" : "website",
"_type" : "blog",
"_id" : "123",
"_version" : 1,
"found" : true,
"_source" : {
"title": "My first blog entry",
"text": "Just trying this out...",
"date": "2014/01/01"
}
}
QUERY 1: 查询1:
{
"query": {
"terms": {
"_id": [
"VALUE1",
"VALUE2"
]
}
}
}
QUERY 2: 查询2:
{
"query": {
"term": {
"_id": {
"value": "VALUE"
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.