弹性搜索全文检索 [英] ElasticSearch Full Text Search
问题描述
我尝试使用正则表达式在弹性搜索java api上运行全文搜索。我的过滤器是这样的:
I try to run full text search with regular expression on elastic search java api. My filter is like this:
FilterBuilder qFilter= FilterBuilders.regexpFilter("_all",
". *"+text+". *");
但它只匹配一个不带短语的单词。我的意思是,例如:
But it matches with only one word not with a phrase. What I mean is, for example:
如果在下面有一个字符串:一二三四五..
,当我的文本字符串如下所示: two
,我们的
, thr
...然后它的工作。
if there is a string in the soruce like: "one two three four five..
" and when my text string is like these: "two
" , "our
", "thr
" ... then it works.
但是当我的realTimeTextIn字符串是两个三个
全文搜索不起作用。我不能搜索一个以上的单词。
But when my realTimeTextIn string is "two three
" full text search doesn't work. I can't search one more than one words.
我在这里缺少什么?
其余的的代码是这样的:
The rest of the codes are something like this:
FilterBuilder qFilter = FilterBuilders.regexpFilter("_all", ".*"+q+".*");
SearchResponse response = ClientProvider.instance().getClient().prepareSearch(index)
.setTypes(type)
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setPostFilter(qFilter)
.setFrom(0).setSize(250).setExplain(true)
.execute()
.actionGet();
感谢您的帮助。
推荐答案
当文本字符串为空或为null时,此连接方法将抛出异常。
您可以使用这样的regexp过滤器。
When text string is empty or null,this join method throws exception. You can use regexp filter like this.
FilterBuilder qFilter = FilterBuilders.regexpFilter("_all",(".*"+q+".*").replace(" ", ".*"));
这篇关于弹性搜索全文检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!