8

I'm running an Elasticsearch server.

I'd like a query such as fifty two meters to match a document containing 52 meters.

Is there any plugin (filter or analyzer) that converts number words to arabic numerals?

Garrett
  • 4,007
  • 2
  • 41
  • 59
  • You could try to use a [synonym token filter](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-synonym-tokenfilter.html) to equate all spelled out number with their numeric equivalent. – Val Dec 14 '16 at 08:26
  • @Val, true, but it would get very long. For example, I would have to specify the synonym `"seven hundred and twenty six => 726"`. I was hoping for some programmatic solution wrapped up into an ES plugin, similar to PyPI's [num2words](https://pypi.python.org/pypi/num2words). – Garrett Dec 14 '16 at 09:01
  • 1
    There are a few projects out there that do this in Java ([one here](https://github.com/gulimran/num2words)), so creating a token filter that leverages it wouldn't be too difficult in my opinion. I'll try to get to it over lunch if I have time :-) – Val Dec 14 '16 at 09:06
  • 1
    Obviously, I didn't get the time to finish this plugin in time. I'll update this thread when done. – Val Dec 21 '16 at 08:15

1 Answers1

4

Currently there is no plug-in for elasticsearch to convert words to number.

I suggest you to create a code that gets raw query as an input and outputs the transformed the query (i.e: convert words to number) for elasticsearch.

You can use this ruby gem (open-source) to convert words to number and vice versa.

NumbersInWords.in_numbers("nineteen sixty five")
1965

And to make things easier ruby intergration for elasticsearch can used to finally query the elasticsearch and get the results.

require 'elasticsearch'

client = Elasticsearch::Client.new log: true

client.transport.reload_connections!

client.cluster.health

client.search q: 'test'
Dulguun
  • 554
  • 5
  • 11