How to perform full text search for a numberic field?

Hi experts,

As the title described, I need to perform full-text search for a field with type "long".

For example:
{id: 100009078}

I need to get it when I search for "78".

Since the mapping cannot be changed once created, how can we do full-text search for the numeric field like we do for the text field?

Any advice is appreciated!

You can't. Full-text search capabilities require building the datastructures needed for a speedy lookup (i.e. the inverted index), and this is done at index time. So if you need to find documents based on prefixes or suffixes like you describe above, you need to index them again with the appropriate field type. You can use multi-fields if you need both numeric and text search, and you can use the reindex api to move your existing index to a new one with the right mapping, but this will still require indexing all documents again (i.e. building the index structure). No way around this.

Mind you that the above example still won't work with the default analyzers since you are looking for suffixes but the default analyzers will treat the whole number as a single token. You need to look into something like the edge analyzer or possibly the reverse token filter in conjunction with the prefix query. I would suggest starting with the edge ngrams since I assume they will be faster than the prefix queries.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.