我是非常新的ElasticSearch,我试图创建一个搜索引擎与模糊查询。
我可以得到结果与模糊搜索与此代码:
{
"query": {
"match": {
"skill": {
"query": "Project management",
"fuzziness": 2,
"prefix_length": 1
}
}
}
}
结果非常好,但我想增加对其他参数的查询结果进行筛选的可能性:例如,我希望仅保留字段“observatory”为以下值之一的文档:[“罗马”,“ESCO”](我需要以数组的形式提供这些值)
我尝试过类似的方法,但我不知道为什么它不起作用:
{
"query": {
"match": {
"skill": {
"query": "Project management",
"fuzziness": 2,
"prefix_length": 1
}
},
"filter" : {
"bool": {
"must": {
"terms": {
"observatory": ["ROME", "ESCO"],
"minimum_should_match": 3
}
}
}
}
}
}
我的问题是:是否可以进行这样的搜索?模糊搜索和过滤?如果可以:怎么做呢?
我的Map如下:
{
"skills": {
"mappings": {
"properties": {
"referentiel_id": {
"type": "text"
},
"observatory": {
"type": "text"
},
"language": {
"type": "text"
},
"type": {
"type": "text"
},
"skill_id_ds_db": {
"type": "text"
},
"skill_id_sm_db": {
"type": "text"
},
"skill": {
"type": "text"
},
"competence_id": {
"type": "text"
}
}
}
}
}
谢谢你的帮助!
编辑:这里是一些来自我的skill
索引的示例值,对于输出,我需要相同的字段
{
"_index": "skills",
"_type": "_doc",
"_id": "kUgpiXkB8y6qOrWRteCU",
"_version": 1,
"_score": 0,
"fields": {
"observatory": [
"ONET"
],
"skill_id_sm_db": [
"null"
],
"skill_id_ds_db": [
"1065629"
],
"skill": [
"Calibrate and test anesthesia equipment."
],
"competence_id": [
"null"
],
"language": [
"en"
],
"referentiel_id": [
"null"
],
"type": [
"hard"
]
}
},
{
"_index": "skills",
"_type": "_doc",
"_id": "PUgpiXkB8y6qOrWRrbKF",
"_version": 1,
"_score": 0,
"fields": {
"observatory": [
"ESCO"
],
"skill_id_sm_db": [
"null"
],
"skill_id_ds_db": [
"1049331"
],
"skill": [
"Types of engraving stone"
],
"competence_id": [
"null"
],
"language": [
"en"
],
"referentiel_id": [
"null"
],
"type": [
"hard"
]
}
},
{
"_index": "skills",
"_type": "_doc",
"_id": "kkgpiXkB8y6qOrWRkASr",
"_version": 1,
"_score": 0,
"fields": {
"observatory": [
"null"
],
"skill_id_sm_db": [
"2254"
],
"skill_id_ds_db": [
"null"
],
"skill": [
"Fédérateur et sait innover pour mobiliser le management, les équipes et les salariés "
],
"competence_id": [
"null"
],
"language": [
"fr"
],
"referentiel_id": [
"8"
],
"type": [
"null"
]
}
}
1条答案
按热度按时间fhity93d1#
可以使用
bool/must/filter
子句的组合添加包含索引数据、Map、搜索查询和搜索结果的工作示例
索引数据:
搜索查询:
搜索结果: