Elasticsearch建议options.text与实际存储的文档不匹配

时间:2018-10-19 02:41:45

标签: elasticsearch elasticsearch-6

我在同一索引中的同一分片中有2个文档。

"profile": {
  "name": "Chinese Flower",
},
"location": {
  "address": {
    "zip": "123",
    "city": "123",
    "address1": "123",
    "state": "123"
  }
} 

"profile": {
  "name": "China Delight",
},
"location": {
  "address": {
    "zip": "abc",
    "city": "abc",
    "address1": "abc",
    "state": "abc"
  },
  "geo": {
    "lon": <some lon>,
    "lat": <some lat>
  }
}

它们都共享相同的映射,

"location": {
  "properties": {
    "address": {
      //stuff
    },
    "geo": {
      "type": "geo_point"
    }
  }
},
"profile": {
  "properties": {
    "name": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        },
        "suggest": {
          "type": "completion",
          "analyzer": "simple",
          "preserve_separators": true,
          "preserve_position_increments": true,
          "max_input_length": 50,
          "contexts": [
            {
              "name": "location",
              "type": "GEO",
              "precision": 6,
              "path": "location.geo"
            }
          ]
        }
      }
    },
  }
}

当我对profile.name上的“ chi”进行建议搜索时,我得到的两个文档均符合预期。但是,出于某种原因,“中国花卉”文档结果具有附加的上下文,并带有“ China Delight”文本,而“中国花卉”文档没有上下文,且具有“ Chinese Delight”文本

具体来说,结果(带我的问题在评论中)是...

"text": "chi",
"offset": 0,
"length": 3,
"options": [
  {
    "text": "China Delight", // why is this china delight? shouldn't it be chinese flower?
    "_index": "rests",
    "_type": "rest",
    "_id": "s1lam2QB9nHU-Kj-_oBW",
    "_score": 1,
    "_source": {
      "profile": {
        "name": "Chinese Flower",
      },
      "location": {
        "address": {
          "zip": "123",
          "city": "123",
          "address1": "123",
          "state": "123"
        }
      },
    },
    "contexts": { // where did this context come from? shouldn't this be on the doc with profile.name === "China Delight"?
      "location": [
        "dr5reg"
      ]
    }
  },
  {
    "text": "Chinese Flower", // why is this chinese flower? shouldn't it be china delight?
    "_index": "myindex",
    "_type": "mytype",
    "_id": "sFndmmQB9nHU-Kj-joB4",
    "_score": 1,
    "_source": {
      "profile": {
        "name": "China Delight",
      },
      "location": {
        "address": {
          "zip": "abc",
          "city": "abc",
          "address1": "abc",
          "state": "abc"
        },
        "geo": {
          "lon": <some lon>,
          "lat": <some lat>
        }
      },
    }
  }
]

当我输入“ chine”或“ china”的文字建议时,我得到了预期的结果。 “ chine”建议导致带有适当文本字段和缺少上下文字段的“ Chinese Flower”的1个结果。 “ china”导致“ China Delight”的1个结果,带有正确的文本字段和 present 上下文字段

那为什么会这样呢?这是什么意思?文本字段实际上告诉我什么?弹性搜索docs这样说

  

文本字段使用索引建议的输入

但是它并没有告诉我为什么我应该关心这个领域。

此外,此上下文不匹配是否可能是我的地理上下文建议查询不起作用的原因?即以下建议查询在我希望给我中国文档时什么也没有提供。我对不同的文档(不是中国软糖或中国花)尝试了相同的查询(替换输入+纬度/经度),并得到了预期的结果。

POST myindex/_search?pretty
{
  "suggest": {
      "my-suggest" : {
          "prefix" : "china", 
          "completion" : { 
              "field" : "profile.name.suggest",
              "size": 10,
              "contexts": {
                    "location": {
                        "lat": <china delight's lat>,
                        "lon": <china delight's lon>,
                        "precision": "5mi"
                    }
                }
          }
      }
  }
}

0 个答案:

没有答案