Elasticsearch Nest获取和更新单个文档

时间:2018-03-08 14:16:48

标签: elasticsearch nest

我希望能够在这里选择单个文档是文档外观的样本

    {
    "_index": "myindex_products",
    "_type": "product",
    "_id": "8Wct9mEBlkDZwzEMRfbG",
"_version": 1,
"_score": 1,
"_source": {
"productId": 5749,
"name": "Product Name Here",
"productCode": "PRODCODE",
"productCategoryId": 73,
"length": 6,
"height": 0,
"productTypeId": 1,
"url": "product-name-here",
"productBrandId": 7,
"width": 0,
"dispatchTimeInDays": 10,
"leadTimeInDays": 6,
"stockAvailable": 0,
"weightKg": 0.001,
"reviewRating": 5,
"reviewRatingCount": 17,
"limitedStock": false,
"price": 16.3,
"productImage": "28796-14654.jpg",
"productCategory": {
"productCategoryId": 73,
"name": "Accessories - New",
"fullPath": "Accessories - New",
"code": "00057"
},
"productSpecification": [
{
"productSpecificationId": 127151,
"productId": 5749,
"specificationId": 232,
"name": "Brand",
"value": "Brand1"
}
,
{
"productSpecificationId": 127175,
"productId": 5749,
"specificationId": 10,
"name": "Guarantee",
"value": "10 years"
}
]
}
}
当我索引时会生成

_id,所以我不想知道这一点我想要更新。我有productId值,我想用它来选择一个文件然后更新/删除如果你知道一个特定的确切值,有没有办法返回一个文件。

由于

1 个答案:

答案 0 :(得分:1)

在建立索引时,您可以使用类似PUT your_index/5749的内容(5749是您的产品ID),ES会将其值用于_id字段,而不是自动生成它。