Elasticserach"更像这样"返回空结果

时间:2018-03-15 15:03:04

标签: elasticsearch morelikethis

我做了一个非常简单的测试来弄清楚我的错误,但没找到它。我创建了两个索引,并且我试图在 ppa 索引中搜索与 ods 索引中的给定文档类似的文档(如此处的第二个示例{ {3}})。

这些是我的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
        }
    }
}

发生了什么事? 请帮助我让它返回空的东西。

1 个答案:

答案 0 :(得分:0)

"更像这样"当您索引大量数据时,查询工作正常。空结果可能是弹性指数中存在的文件很少的症状。