Lucene style queries from the Java API?


(Jake) #1

I'm using version 0.11 and the Java API to search on my 'title' field like so:

SearchResponse response = client.prepareSearch("documents")
.setQuery(QueryBuilders.termQuery("title", "jakarta apache"))
.execute()
.actionGet();

How would I represent the following Lucene style query in the Java API?

title:"jakarta apache" NOT title:"Apache Lucene"

[jake]


(Lukáš Vlček) #2

Hi,
I think you should be fine using QueryBulders.boolQuery()
Regards,
Lukas

On Mon, Oct 4, 2010 at 6:23 PM, Jake jakebartlett@gmail.com wrote:

I'm using version 0.11 and the Java API to search on my 'title' field like
so:

SearchResponse response = client.prepareSearch("documents")
.setQuery(QueryBuilders.termQuery("title", "jakarta
apache"))
.execute()
.actionGet();

How would I represent the following Lucene style query in the Java API?

title:"jakarta apache" NOT title:"Apache Lucene"

[jake]

View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Lucene-style-queries-from-the-Java-API-tp1630758p1630758.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


(Shay Banon) #3

Hey,

You have two options. The first is to use a queryString or field queries
and provide the query you provided. It will be parsed into the proper Lucene
Query structure. Another optino is to use what Lukas suggested and build
that query yourself using the boolQuery option (which maps to Lucene
BooleanQuery). All the queries are listed in the query_dsl page (
http://www.elasticsearch.com/docs/elasticsearch/rest_api/query_dsl/), and
you can find all of them in the QueryBuilders and FilterBuilders factories.

-shay.banon

On Wed, Oct 6, 2010 at 8:08 AM, Lukáš Vlček lukas.vlcek@gmail.com wrote:

Hi,
I think you should be fine using QueryBulders.boolQuery()
Regards,
Lukas

On Mon, Oct 4, 2010 at 6:23 PM, Jake jakebartlett@gmail.com wrote:

I'm using version 0.11 and the Java API to search on my 'title' field like
so:

SearchResponse response = client.prepareSearch("documents")
.setQuery(QueryBuilders.termQuery("title", "jakarta
apache"))
.execute()
.actionGet();

How would I represent the following Lucene style query in the Java API?

title:"jakarta apache" NOT title:"Apache Lucene"

[jake]

View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Lucene-style-queries-from-the-Java-API-tp1630758p1630758.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


(system) #4