I have the following mapping:

"urls": {
   "type": "string", 
   "index_name": "url", 
   "boost": "1",
   "analyzer": "aurlemail",
   "store": "yes"
 }

and the analyzer defined as following:

index.analysis.analyzer.aurlemail:
  type: custom
  tokenizer: uax_url_email
  filter: lowercase, fngramurl

index.analysis.filter.fngramurl:
  type: nGram
  min_gram: 3
  max_gram: 20

and I have http://www.google.com and http://www.google.com/hugo added to the index, two separate documents.

when I perform a termQuery on the specific field I get the expected hits (e.g. I search for www.google.com, or google.com), but when I just want a simple query, where I don't define any fields I get zero results.

the code looks like this:

client().prepareSearch("myindex").setQuery("www.google.com")
  .execute().actionGet();

How do I get the results without having to specify a termQuery, the specific field respectively?

update

more specific: I want to receive the hits also when I just query for google, or even com. This should be available in the index, due to the defined analyzer (I suppose), but neither a matchQuery nor a stringQuery work as expected

update 2

the version of ES in question is 1.1.0

有帮助吗?

解决方案

Use query string queries with default field as "_all".

client().prepareSearch("myindex").setQuery(QueryBuilders.queryString("www.google.com")
.defaultField("_all")).execute().actionGet();

Update

Match query

 client().prepareSearch("myindex").setQuery(QueryBuilders.matchQuery("_all", "google")).execute().actionGet();

Hope it helps..!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top