【发布时间】:2019-12-25 20:59:25
【问题描述】:
我正在尝试创建一个允许按名称和类型进行搜索的搜索查询。 我已经索引了这些值,我在 Elasticsearch 中的记录如下所示:
{
_index: "assets",
_type: "asset",
_id: "eAOEN28BcFmQazI-nngR",
_score: 1,
_source: {
name: "test.png",
mediaType: "IMAGE",
meta: {
content-type: "image/png",
width: 3348,
height: 1890,
},
createdAt: "2019-12-24T10:47:15.727Z",
updatedAt: "2019-12-24T10:47:15.727Z",
}
}
那么,例如,我将如何创建一个查询来查找所有名称为“test”并且是图像的资产?
我尝试了 multi_mach 查询,但没有返回正确的结果:
{
"query": {
"multi_match" : {
"query": "*test* IMAGE",
"type": "cross_fields",
"fields": [ "name", "mediaType" ],
"operator": "and"
}
}
}
上面的查询返回 0 个结果,如果我将运算符更改为“或”,它将返回所有这些 IMAGE 类型的资产。
任何建议将不胜感激。蒂亚!
编辑:添加映射 下面是映射:
{
"assets": {
"aliases": {},
"mappings": {
"properties": {
"__v": {
"type": "long"
},
"createdAt": {
"type": "date"
},
"deleted": {
"type": "date"
},
"mediaType": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"meta": {
"properties": {
"content-type": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"width": {
"type": "long"
},
"height": {
"type": "long"
}
}
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"originalName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"updatedAt": {
"type": "date"
}
}
},
"settings": {
"index": {
"creation_date": "1575884312237",
"number_of_shards": "1",
"number_of_replicas": "1",
"uuid": "nSiAoIIwQJqXQRTyqw9CSA",
"version": {
"created": "7030099"
},
"provided_name": "assets"
}
}
}
}
【问题讨论】:
-
您能发布您的索引映射和设置吗?
-
@tomslabbaert 我已经更新了我的问题以包含映射和设置
标签: elasticsearch elasticsearch-query