ankane / searchkick

Intelligent search made easy
MIT License
6.56k stars 758 forks source link

"similar" doesn't work for numeric fields #1125

Closed bbugh closed 6 years ago

bbugh commented 6 years ago

I'm guessing that this might be an elastic limitation because the "more_like_this" says it only supports text fields, but I don't get an error from searchkick so maybe there's something else that can happen.

When we run code like this, we get no results:

model = Model.find_by(special_number: 1088)
model.similar(fields: [:special_number])

There are definitely other models that have number matching 1088. The query it generates:

> Model.find(177).similar(fields: [:special_number])
{
  "size": 10,
  "from": 0,
  "query": {
    "bool": {
      "must": {
        "more_like_this": {
          "like": "10260",
          "min_doc_freq": 1,
          "min_term_freq": 1,
          "analyzer": "searchkick_search2",
          "fields": [
            "special_number.analyzed"
          ]
        }
      },
      "filter": [
        {
          "bool": {
            "must_not": {
              "term": {
                "_id": "177"
              }
            }
          }
        }
      ]
    }
  },
  "timeout": "11s",
  "_source": false
}

No error, but no results either.

ankane commented 6 years ago

Hey @bbugh, similar is only designed to work with text fields.

bbugh commented 6 years ago

Thanks @arkane. Would you accept a small PR for the docs for this? I spent too much time digging through Elastic's docs as well and would like to save someone else the time, since it "fails" silently.

ankane commented 6 years ago

Sure, happy to review a PR for it.