Elasticsearch改变相似性不起作用

时间:2017-05-02 19:15:14

标签: elasticsearch similarity

更改索引的相似度算法不起作用。我不想比较BM25和TF-IDF,但我总能得到相同的结果。我使用的是Elasticsearch 5.x。

我已经尝试了一切。将属性的相似性设置为classicBM25或不设置任何内容

"properties": {
           "content": {
              "type": "text",
              "similarity": "classic"
           },

我还尝试在settings中设置我的索引的默认相似度,并在properties

中使用它
"settings": {
     "index": {
        "number_of_shards": "5",
        "provided_name": "test",
        "similarity": {
           "default": {
              "type": "classic"
           }
        },
        "creation_date": "1493748517301",
        "number_of_replicas": "1",
        "uuid": "sNuWcT4AT82MKsfAB9JcXQ",
        "version": {
           "created": "5020299"
        }
     }

查询即时测试看起来像这样:

{
  "query": {
    "match": {
      "content": "some search query"
    }
  }
}

1 个答案:

答案 0 :(得分:1)

我在下面创建了一个示例:

DELETE test
PUT test
{
  "mappings": {
    "book": {
      "properties": {
        "content": {
          "type": "text",
          "similarity": "BM25"
        },
        "subject": {
          "type": "text",
          "similarity": "classic"
        }
      }
    }
  }
}

POST test/book/1
{
  "subject": "A neutron star is the collapsed core of a large (10–29 solar masses) star. Neutron stars are the smallest and densest stars known to exist.[1] Though neutron stars typically have a radius on the order of 10 km, they can have masses of about twice that of the Sun.",
  "content": "A neutron star is the collapsed core of a large (10–29 solar masses) star. Neutron stars are the smallest and densest stars known to exist.[1] Though neutron stars typically have a radius on the order of 10 km, they can have masses of about twice that of the Sun."
}
POST test/book/2
{
  "subject": "A quark star is a hypothetical type of compact exotic star composed of quark matter, where extremely high temperature and pressure forces nuclear particles to dissolve into a continuous phase consisting of free quarks. These are ultra-dense phases of degenerate matter theorized to form inside neutron stars exceeding a predicted internal pressure needed for quark degeneracy.",
  "content": "A quark star is a hypothetical type of compact exotic star composed of quark matter, where extremely high temperature and pressure forces nuclear particles to dissolve into a continuous phase consisting of free quarks. These are ultra-dense phases of degenerate matter theorized to form inside neutron stars exceeding a predicted internal pressure needed for quark degeneracy."
}

GET test/_search?explain
{
  "query": {
    "match": {
      "subject": "neutron"
    }
  }
}
GET test/_search?explain
{
  "query": {
    "match": {
      "content": "neutron"
    }
  }
}

subjectcontent字段具有不同的相似性定义,但在我提供的两个文档(来自维基百科)中,它们具有相同的文本。运行这两个查询,您将在解释中看到类似的结果,并在结果中得到不同的分数:

  • 来自第一个查询:"description": "idf, computed as log((docCount+1)/(docFreq+1)) + 1 from:"
  • 来自第二个:"description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",