我有下面的映射,
{
"wms": {
"mappings": {
"item": {
"properties": {
"barcode": {
"type": "string"
},
"comments": {
"type": "string"
},
"id": {
"type": "long"
},
"sku": {
"type": "nested",
"properties": {
"brandName": {
"type": "string"
},
"code": {
"type": "string"
},
"id": {
"type": "long"
}
}
}
}
}
}
}
}
及以下数据。
{
"_index": "wms",
"_type": "item",
"_id": "100006868381",
"_score": 1.0,
"_source": {
"id": 100006868381,
"createdBy": null,
"createdOn": null,
"lastModifiedOn": null,
"barcode": "100006868381",
"sku": {
"id": 396829,
"createdBy": null,
"createdOn": null,
"lastModifiedOn": null,
"name": null,
"code": "KIRAHDBG00598",
"lastUser": null,
"adminDisabled": null,
"description": null,
"vendorArticleNo": null,
"vendorArticleName": null,
"size": null,
"brandId": null,
"brandName": "KIARA",
"brandCode": null,
"articleTypeId": null,
"articleTypeName": null,
"articleTypeCode": null,
"remarks": null,
"jitSourced": null,
"gtin": null,
"enabled": null,
"version": null
},
"quality": null,
"itemStatus": null,
"warehouseId": null,
"enabled": null,
"poId": null,
"poBarcode": null,
"comments": "Created for PO: RNSI233380213-00Thu Aug 21 10:40:36 IST 2014",
"orderId": null,
"bin": null,
"lotId": null,
"lotBarcode": null,
"poSkuId": null,
"grnSkuId": null,
"grnBarcode": null,
"inwardedOn": null,
"rejectReason": null,
"rejectReasonDescription": null,
"cartonBarcode": null
}
}
我正在使用 spring-elasticsearch 数据但没有存储库。我的意思是使用模板本身。当我对条形码进行搜索时,它工作正常。当我运行嵌套查询时,一切似乎都很好sku.id
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"nested": {
"filter": {
"term": {
"sku.id": "396829"
}
},
"path": "sku"
}
}
}
}
}
但是当我搜索时事情不正常sku.code
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"nested": {
"filter": {
"term": {
"sku.code": "KIRAHDBG00598"
}
},
"path": "sku"
}
}
}
}
}
我正在使用下面的代码进行搜索。
filterBuilder = FilterBuilders.termFilter(name, value);
if (name.contains(".")) {
String firstPart = name.split("\\.")[0];
return FilterBuilders.nestedFilter(firstPart, filterBuilder);
}
Pageable pageable = new PageRequest(0, 20);
SearchQuery searchQuery = new NativeSearchQueryBuilder()
.withQuery(QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(), filterBuilder))
.withPageable(pageable)
.build();
Page<E> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, this.entryClass);
你能告诉我我错过了什么吗?