[英]ElasticSearch Full Text Search
I try to run full text search with regular expression on elastic search java api. 我尝试在弹性搜索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: 我的意思是,例如:
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. 如果soruce中有一个字符串,例如:“ one two three four five..
”,而当我的文本字符串如下:“ two
”,“ our
”,“ thr
” ...则它起作用。
But when my realTimeTextIn string is " two three
" full text search doesn't work. 但是,当我的realTimeTextIn字符串为“ two three
”时,全文搜索将不起作用。 I can't search one more than one words. 我不能只搜索一个字。
What I'm missing here? 我在这里想念的是什么?
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();
Thanks for helps. 感谢您的帮助。
When text string is empty or null,this join method throws exception. 当文本字符串为空或null时,此join方法将引发异常。 You can use regexp filter like this. 您可以像这样使用regexp过滤器。
FilterBuilder qFilter = FilterBuilders.regexpFilter("_all",(".*"+q+".*").replace(" ", ".*"));
That is an interesting question. 这是一个有趣的问题。 I found something like phrase queries and phrase matching: http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/phrase-matching.html http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_phrase_search.html 我发现了类似短语查询和短语匹配的内容: http : //www.elasticsearch.org/guide/en/elasticsearch/guide/current/phrase-matching.html http://www.elasticsearch.org/guide/en/elasticsearch /guide/current/_phrase_search.html
In java api we can do this for query (I tested this): 在Java api中,我们可以针对查询执行此操作(我对此进行了测试):
SearchResponse response = client.prepareSearch(index)
.setTypes(type)
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setFrom(0).setSize(250).setExplain(true).setQuery(QueryBuilders.matchPhraseQuery(field, "one two"))
.execute()
.actionGet();
I'm sorry, but I didn't find any solution. 很抱歉,但没有找到任何解决方案。
You can try build a script filter (insert plain json to your filter instead of java method) or something called query filter: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query-filter.html 您可以尝试构建脚本过滤器(将纯json而不是java方法插入到过滤器中)或称为查询过滤器的内容: http : //www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-query -filter.html
I hope that it helped you a little. 希望对您有所帮助。
FilterBuilder qFilter= FilterBuilders.regexpFilter( "_all",". *"+Joiner.on(".*").join(text.split(" "))+". *");
I happened to make a full text search like this using query builder 我碰巧使用查询生成器进行了这样的全文搜索
QueryBuilder queryBuilder = QueryBuilders.multiMatchQuery(query)
.field("name", 2.0f)
.field("email")
.field("title")
.field("jobDescription", 3.0f)
.type(MultiMatchQueryBuilder.Type.PHRASE_PREFIX);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.