预定义术语映射
Predefined Term Mapping
我还没有使用过 Elasticsearch,所以请原谅我的错误描述。我想知道是否可以将 Elasticsearch 配置为执行以下操作 - 我在 MongoDB 中遇到了一些问题,因为全文搜索功能似乎有点受限。
Here's my problem - when I do a search for the term Korea
I do not
want it to match North Korea
or N. Korea
in the document.
假设搜索 Korea
大约是 South Korea
。这显然不同于同义词,因为它有点相反。 South Korea
的短语搜索在这里是不可能的,因为它不适用于我的问题。这可能吗?
我会接受 MongoDB 或 Elasticsearch 的答案。
如果您使用这样的查询会怎样:
{
"query": {
"bool": {
"should": [
{
"match": {
"some_field": "korea"
}
},
{
"query_string": {
"query": "-some_field:(\"north korea\")"
}
},
{
"query_string": {
"query": "-some_field:(\"n. korea\")"
}
}
]
}
}
}
它的作用是这样的:
- 如果该字段内容与 "korea" 匹配,则它会收到分数
- 如果该字段再次不匹配 "north korea" 它会得到一些分数提升
- 同样,如果不匹配,"n. korea" 会得到一些额外的分数。
基本上,匹配"korea",不匹配"north korea",不匹配"n. korea".
,分数都会增加
例如,对于这样的文档
POST /my_index/test/1
{
"text": "North Korea"
}
POST /my_index/test/2
{
"text": "Korea"
}
POST /my_index/test/3
{
"text": "N. Korea"
}
POST /my_index/test/4
{
"text": "South Korea"
}
上面的查询将return这样:
"hits": [
{
"_index": "korea",
"_type": "test",
"_id": "2",
"_score": 1.4471208,
"_source": {
"text": "Korea"
}
},
{
"_index": "korea",
"_type": "test",
"_id": "4",
"_score": 1.4227209,
"_source": {
"text": "South Korea"
}
},
{
"_index": "korea",
"_type": "test",
"_id": "1",
"_score": 0.48779577,
"_source": {
"text": "North Korea"
}
},
{
"_index": "korea",
"_type": "test",
"_id": "3",
"_score": 0.48779577,
"_source": {
"text": "N. Korea"
}
}
]
得分最高的是与朝鲜无关的文件。
我还没有使用过 Elasticsearch,所以请原谅我的错误描述。我想知道是否可以将 Elasticsearch 配置为执行以下操作 - 我在 MongoDB 中遇到了一些问题,因为全文搜索功能似乎有点受限。
Here's my problem - when I do a search for the term
Korea
I do not want it to matchNorth Korea
orN. Korea
in the document.
假设搜索 Korea
大约是 South Korea
。这显然不同于同义词,因为它有点相反。 South Korea
的短语搜索在这里是不可能的,因为它不适用于我的问题。这可能吗?
我会接受 MongoDB 或 Elasticsearch 的答案。
如果您使用这样的查询会怎样:
{
"query": {
"bool": {
"should": [
{
"match": {
"some_field": "korea"
}
},
{
"query_string": {
"query": "-some_field:(\"north korea\")"
}
},
{
"query_string": {
"query": "-some_field:(\"n. korea\")"
}
}
]
}
}
}
它的作用是这样的:
- 如果该字段内容与 "korea" 匹配,则它会收到分数
- 如果该字段再次不匹配 "north korea" 它会得到一些分数提升
- 同样,如果不匹配,"n. korea" 会得到一些额外的分数。
基本上,匹配"korea",不匹配"north korea",不匹配"n. korea".
,分数都会增加例如,对于这样的文档
POST /my_index/test/1
{
"text": "North Korea"
}
POST /my_index/test/2
{
"text": "Korea"
}
POST /my_index/test/3
{
"text": "N. Korea"
}
POST /my_index/test/4
{
"text": "South Korea"
}
上面的查询将return这样:
"hits": [
{
"_index": "korea",
"_type": "test",
"_id": "2",
"_score": 1.4471208,
"_source": {
"text": "Korea"
}
},
{
"_index": "korea",
"_type": "test",
"_id": "4",
"_score": 1.4227209,
"_source": {
"text": "South Korea"
}
},
{
"_index": "korea",
"_type": "test",
"_id": "1",
"_score": 0.48779577,
"_source": {
"text": "North Korea"
}
},
{
"_index": "korea",
"_type": "test",
"_id": "3",
"_score": 0.48779577,
"_source": {
"text": "N. Korea"
}
}
]
得分最高的是与朝鲜无关的文件。