【发布时间】:2018-08-24 11:11:15
【问题描述】:
我做了一个非常简单的测试来找出我的错误,但没有找到。我创建了两个索引,并尝试在 ppa 索引中搜索与 ods 索引中的给定文档相似的文档(就像这里的第二个示例 https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-mlt-query.html )。
这些是我对 ppa 索引的设置、映射和文档:
PUT /ppa
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0,
"analysis": {
"filter": {
"brazilian_stop": {
"type": "stop",
"stopwords": "_brazilian_"
},
"brazilian_stemmer": {
"type": "stemmer",
"language": "brazilian"
}
},
"analyzer": {
"brazilian": {
"tokenizer": "standard",
"filter": [
"lowercase",
"brazilian_stop",
"brazilian_stemmer"
]
}
}
}
}
}
PUT /ppa/_mapping/ppa
{"properties": {"descricao": {"type": "text", "analyzer": "brazilian"}}}
POST /_bulk
{"index":{"_index":"ppa","_type":"ppa"}}
{"descricao": "erradicar a pobreza"}
{"index":{"_index":"ppa","_type":"ppa"}}
{"descricao": "erradicar a pobreza"}
这些是我对 ods 索引的设置、映射和文档:
PUT /ods
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0,
"analysis": {
"filter": {
"brazilian_stop": {
"type": "stop",
"stopwords": "_brazilian_"
},
"brazilian_stemmer": {
"type": "stemmer",
"language": "brazilian"
}
},
"analyzer": {
"brazilian": {
"tokenizer": "standard",
"filter": [
"lowercase",
"brazilian_stop",
"brazilian_stemmer"
]
}
}
}
}
}
PUT /ods/_mapping/ods
{"properties": {"metaodsdescricao": {"type": "text", "analyzer": "brazilian"},"metaodsid": {"type": "integer"}}}
POST /_bulk
{"index":{"_index":"ods","_type":"ods", "_id" : "1" }}
{ "metaodsdescricao": "erradicar a pobreza","metaodsid": 1}
{"index":{"_index":"ods","_type":"ods", "_id" : "2" }}
{"metaodsdescricao": "crianças que vivem na pobreza", "metaodsid": 2}
现在,这个搜索不起作用:
GET /ppa/ppa/_search
{
"query": {
"more_like_this" : {
"fields" : ["descricao"],
"like" : [
{
"_index" : "ods",
"_type" : "ods",
"_id" : "1"
}
],
"min_term_freq" : 1,
"min_doc_freq" : 1,
"max_query_terms" : 20
}
}
}
但是这个确实有效:
GET /ppa/ppa/_search
{
"query": {
"more_like_this" : {
"fields" : ["descricao"],
"like" : ["erradicar a pobreza"],
"min_term_freq" : 1,
"min_doc_freq" : 1,
"max_query_terms" : 20
}
}
}
发生了什么? 请帮我让这个返回不是空的。
【问题讨论】:
-
您的文档有名为“metaodsdescricao”的字段,但您的查询使用了名为“descricao”的字段?应该是 *descricao 吗?
-
我相信名字都是正确的。 ppa 映射有一个名为 descricao 的字段,而 ods 映射有一个名为 metaodsdescricao 的字段。我的查询是在其 descicao 字段中搜索 ppa。因此,我认为这部分是正确的。
-
糟糕,我没有注意到您有两个索引。我认为字段必须匹配。您可以尝试 * 或两个字段,看看它是否可以作为一种解决方法,但不确定
-
你是对的。如果我使两个字段具有相同的名称,则查询将返回预期结果。是否需要这个要求?我想知道它是如何实现的。
-
这是 ES 人的问题 :)
标签: elasticsearch morelikethis