1 回答

TA貢獻1804條經驗 獲得超8個贊
由于在數據類型上使用參數,然后使用true使其工作,如此鏈接中所述,因此發生了此問題。fuzzinessnumericlenientremoves format-based errors, such as providing a text query value for a numeric field, are ignored.
下面是您在嘗試在數值數據類型上使用時遇到的錯誤。fuzziness
原因“:”只能對關鍵字和文本字段使用模糊查詢 - 不能對類型為 [整數] 的 [age] 使用模糊查詢”
當您添加 時,上述錯誤會消失,但不會返回任何文檔。"lenient" : true
要使其正常工作,只需從搜索查詢中刪除和參數,它就可以工作,因為 Elasticsearch 會自動將有效轉換為有效值,反之亦然,如強制文章中所述。fuzzinesslenientstringnumeric
使用 REST API 顯示它的工作示例
指數定義
{
"mappings": {
"properties": {
"age" :{
"type" : "integer"
}
}
}
}
索引示例文檔
{
"age" : "25" --> note use of `""`, sending it as string
}
{
"age" : 28 :- note sending numneric value
}
字符串格式的搜索查詢
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"query": "28", --> note string format
"fields": [
"age" --> note you can add more fields
]
}
}
]
}
}
}
搜索結果
"hits": [
{
"_index": "so_numberic",
"_type": "_doc",
"_id": "1",
"_score": 1.0,
"_source": {
"program_number": "123456789",
"age": "28"
}
}
]
數字格式的搜索查詢
{
"query": {
"match" : { --> query on single field.
"age" : {
"query" : 28 --> note numeric format
}
}
}
}
結果
"hits": [
{
"_index": "so_numberic",
"_type": "_doc",
"_id": "1",
"_score": 1.0,
"_source": {
"program_number": "123456789",
"age": "28"
}
}
]
如前所述,顯示您的 和 不會帶來任何結果。fuzzinesslenient
搜索查詢
{
"query": {
"match": {
"age": {
"query": 28,
"fuzziness": 2,
"lenient": true
}
}
}
}
結果
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": { --> note 0 results.
"total": {
"value": 0,
"relation": "eq"
},
"max_score": null,
"hits": []
}
}
添加回答
舉報