ElasticSearch: Full-Text Search made easy

杀马特。学长 韩版系。学妹 提交于 2019-12-10 23:54:59

问题


I am investigate possibility to switch to ElasticSearch from SphinxSearch.

What is good about SphinxSearch - full-text search just work out of the bot on pretty good level. Make it work on ElasticSearch appeared not as easy as I expected.

In my project I have search box with typeahead, means I stype Clint E and see dropdown with results including Clint Eastwood on the first place. Type robert down and see Robert Downey Jr. on the first place. All this I achieved with SphinxSearch out of the box just providing it my DB credentials and SQL query to pull the necessary fields.

On the other hand, with ElasticSearch I can't get satisfying results even after a day of reading about Fuzzy Like This Query, matching, partial matching and other. A lot of information but it does not make task easier. I feel like I need to be PhD in search just to make it work at simplest level.

So far I ended up with such configuration

{
    "settings": {
        "analysis": {
            "analyzer": {
                "stem": {
                    "tokenizer": "standard",
                    "filter": [
                        "standard",
                        "lowercase",
                        "stop",
                        "porter_stem"
                    ]
                }
            }
        }
    },
    "mappings": {
        "movies": {
            "dynamic": true,
            "properties": {
                "title": {
                    "type": "string",
                    "analyzer": "stem"
                }
            }
        }
    }
}

The Query look like this:

{
    "query": {
        "query_string": {
            "query": "clint eastw"
            "default_field": "title"
        }
    }
}

But quality of search in this case is not satisfying at all - back to my example, it can not find Clint Eastwood profile until I type his name completely.

Then I tried to use

{
    "query": {
        "fuzzy_like_this": {
            "fields": [
                "title"
            ],
            "like_text": "clint eastw",
            "max_query_terms": 25,
            "fuzziness": 0.5
        }
    }
}

It helps but not much, now I can find what I need with shorter request clint eastwo and after some manipulations with parameters with clint eastw but still not encouraging.

So I wonder, is there a simple recipe how to cook full-text search with ElasticSearch and get decent quality of results. I spend a day reading but didn't find the solution.

Couple of images to demonstrate what I am talking about:

Elastic, name almost complete but no expected result, note that there is no better match as well.

One letter after, elastic found it!

At the same moment Sphinx shining :)


回答1:


Elasticsearch ships with auto completion suggester. You need not put this into query functioanility , the way it works is on token level and not on partial token level. Go for completion suggester , it also have support for fuzzy logic.



来源:https://stackoverflow.com/questions/33096686/elasticsearch-full-text-search-made-easy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!