Reputation: 495
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:
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.
But when my realTimeTextIn string is "two three
" full text search doesn't work. 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.
Upvotes: 2
Views: 2043
Reputation: 806
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);
Upvotes: 0
Reputation: 591
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(" ", ".*"));
Upvotes: 2
Reputation: 543
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
In java api we can do this for query (I tested this):
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
I hope that it helped you a little.
FilterBuilder qFilter= FilterBuilders.regexpFilter(
"_all",". *"+Joiner.on(".*").join(text.split(" "))+". *");
Upvotes: 1