了解Elasticsearch多值字段

时间:2018-03-27 20:44:28

标签: elasticsearch multivalue

我正在尝试理解position_increment_gap,因为它在Elasticsearch文档中有解释https://www.elastic.co/guide/en/elasticsearch/guide/current/_multivalue_fields_2.html

我创建了与示例中相同的索引并插入了单个文档

PUT /my_index/groups/1
{
    "names": [ "John Abraham", "Lincoln Smith", "Justin Trudeau"]
}

然后我尝试对亚伯拉罕林肯进行短语查询,并按预期匹配

GET /my_index/groups/_search
{
    "query": {
        "match_phrase": {
            "names": "Abraham Lincoln"
        }
    }
}

{
  "took": 25,
  "timed_out": false,
  "_shards": {
  "total": 5,
  "successful": 5,
  "skipped": 0,
  "failed": 0
},
"hits": {
  "total": 1,
  "max_score": 0.5753642,
  "hits": [
  {
    "_index": "names",
    "_type": "doc",
    "_id": "1",
    "_score": 0.5753642,
    "_source": {
      "names": [
        "john abraham",
        "lincoln smith",
        "justin trudeau"
      ]
    }
  }
  ]
} 
}

文档解释说匹配发生是因为ES产生了令牌john abraham lincoln smith justin trudeau并且它建议插入position_increment_gap为100以避免匹配亚伯拉罕林肯,除非我有100的斜率。

我将索引更改为position_increment_gap为1,如下所示:

PUT names
{
  "mappings": {
    "doc": {
      "properties": {
        "names": {
          "type":"text",
          "position_increment_gap": 1
        }
      }
    }
  }
}

如果我理解文档,使用1的差距应该允许我匹配“亚伯拉罕史密斯”。但它不匹配。 “亚伯拉罕·林肯”,“亚伯拉罕·贾斯汀”或“亚伯拉罕·特鲁多”也不是。 “lincoln smith”,“john abraham”和“justin trudeau”都继续相配。

我一定是误解了文档。

感谢您的任何建议。

0 个答案:

没有答案
相关问题