首页 > 解决方案 > match query returns exact values only in elasticsearch

问题描述

I have following documents:

    {
        "_index": "testrest",
        "_type": "testrest",
        "_id": "sadfasdfw1",
        "_score": 1,
        "_source": {,
            "s_item_name": "Create",
            "request_id": "35",
            "confidence": "0.5",
        }
    },
    {
        "_index": "testrest",
        "_type": "testrest",
        "_id": "asdfds",
        "_score": 1,
        "_source": {,
            "s_item_name": "Update",
            "request_id": "35",
            "confidence": "0.3333",
        }
    },

I am trying to get results for request_id of 35 and their confidence values.

For eg. if input is only 0. then both results should be displayed.

And if input is 0.5 then only first doc., and if 0.3 only second doc.

Here's what I tried:

 {
  "query": { 
    "bool": { 
      "must": [ 
        { "match":  { "confidence_score": "0.33" }}
      ],
      "filter": {
        "term": {
            "request_id": "35"
        }
      }
    }
  }
}

This gives 0 results. Since it requires exact values only, like 0.5 or 0.3333.

I thought match works for this instead of term.

How do I make the query similar to LIKE operator in SQL?

标签: elasticsearch

解决方案


就像我应该建议你看一下wildcard, prefix or match_phrase弹性搜索中的类型,或者如果你使用的是最新版本,你可以使用 ES 插件编写 SQL 语句。


推荐阅读