我有一个包含文档的索引,文档中包含一组称为产品的对象。产品具有一个名为feed_id的字段,我将其映射为products.feed_id
(文本)。
但是当我执行匹配查询时,我只是找到匹配的feed_id在数组第一行中的文档。我是否需要将产品映射为嵌套(我已经尝试过了,但是还行不通,我是否也需要映射数组中的字段?)
我添加了映射/查询和一个未找到的示例文档。 (如果feed_id是数组的第一行,则会找到其他文档)
映射
{
"products-nl" : {
"aliases" : { },
"mappings" : {
"product" : {
"dynamic" : "false",
"properties" : {
"brand" : {
"type" : "text"
},
"brand_keyword" : {
"type" : "keyword"
},
"description_short" : {
"type" : "text"
},
"eancode" : {
"type" : "text"
},
"full_title" : {
"type" : "text"
},
"price" : {
"type" : "float"
},
"products" : {
"properties" : {
"category_string" : {
"type" : "text"
},
"feed_id" : {
"type" : "integer"
},
"full_shop_title" : {
"type" : "text"
},
"shop_title" : {
"type" : "keyword"
},
"shop_title_search" : {
"type" : "text"
},
"title" : {
"type" : "text"
}
}
},
"providers" : {
"type" : "nested"
},
"shop_amount" : {
"type" : "integer"
},
"shop_title_search" : {
"type" : "text"
},
"timestamp" : {
"type" : "date"
},
"title" : {
"type" : "keyword"
},
"total_price" : {
"type" : "float"
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1547042901221",
"number_of_shards" : "5",
"number_of_replicas" : "0",
"uuid" : "OUXvA4kiTJCs1L30ZoYv1w",
"version" : {
"created" : "6050499"
},
"provided_name" : "products-nl"
}
}
}
}
查询
GET products-nl/_search
{
"size": 3000,
"query": {
"match": {
"products.feed_id": 15621
}
}
}
文档(应该说是因为feed_id在其中,但在产品的第3行上)。
{
"_source": {
"title": "Disney Frozen 18 Inch 28 cm Meisjes Terugtraprem Mintgroen",
"products": {
"0": {
"title": "Disney Frozen 18 Inch 28 cm Meisjes Terugtraprem Mintgroen",
"feed_id": "53"
},
"2": {
"title": "Disney Frozen 18 Inch 28 cm Meisjes Terugtraprem Mintgroen",
"feed_id": "3564"
},
"3": {
"title": "Kinderfiets 18 Inch Meisjes Disney Frozen 51861",
"feed_id": "15621"
},
"4": {
"title": "Disney Frozen meisjesfiets 18 inch",
"feed_id": "3251"
},
"5": {
"title": "Disney Frozen 18 Inch Meisjesfiets",
"feed_id": "6192"
},
"6": {
"title": "Disney Frozen 18 inch meisjesfiets 95 afgemonteerd",
"feed_id": "460"
},
"7": {
"title": "Disney Frozen 18 inch meisjesfiets",
"feed_id": "15882"
},
"8": {
"title": "Disney Frozen 95 Meisjes 2018 18inch Blauw",
"feed_id": "180"
},
"9": {
"title": "Disney Frozen 18 inch meisjesfiets 95 afgemonteerd",
"feed_id": "399"
}
}
}
}
答案 0 :(得分:1)
我认为原因是(1)您已禁用动态映射,并且(2)您的products
项目的结构与定义的映射不匹配。因此,即使这些字段出现在_source
字段(see documentation)中,也不会对其进行索引(即不可搜索)。
让我更加精确。 products
项的映射将匹配以下内容:
"products": [
{
"title": "Disney Frozen 18 Inch 28 cm Meisjes Terugtraprem Mintgroen",
"feed_id": "53"
},
...
{
"title": "Kinderfiets 18 Inch Meisjes Disney Frozen 51861",
"feed_id": "15621"
},
...
]
相反,您有这个:
"products": {
"0": {
"title": "Disney Frozen 18 Inch 28 cm Meisjes Terugtraprem Mintgroen",
"feed_id": "53"
},
...
"3": {
"title": "Kinderfiets 18 Inch Meisjes Disney Frozen 51861",
"feed_id": "15621"
},
...
}
,这是一个非常不同的映射。由于这些项目与映射不匹配,并且由于您禁用了动态映射,因此products
项目不可搜索。