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": []
}
}
添加回答
举报
