Java Query API

Hi,

I'm very newbie to ElasticSearch. I use Java API to build the bool query as
following:

{
"bool" : {
"must" : [ {
"text" : {
"content" : {
"query" : "404 get",
"type" : "phrase",
"operator" : "AND"
}
}
}, {
"terms" : {
"host" : [ "localhost" ]
}
} ]
}
}

I got no doc if doing the query with Java API but doing the query with
curl, some docs returned.

SearchResponse response = client.prepareSearch(getIndices())
                .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
                .setQuery(query).addFields(returnFields()).setFrom(from)
                .setSize(size).execute().actionGet();

What's wrong with my java code?

Thanks,
Duy

try this instead:

QueryBuilder query = boolQuery().must(textQuery("content", "404 get"
).type(Type.PHRASE).operator(Operator.AND)).should(termsQuery("host",
"localhost"));

SearchResponse response = client.prepareSearch(getIndices())
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(query).addFields(returnFields()).setFrom(from)
.setSize(size).execute().actionGet();
Cheers

On Tuesday, July 17, 2012 6:41:40 AM UTC-4, Duy Do wrote:

Hi,

I'm very newbie to Elasticsearch. I use Java API to build the bool query
as following:

{
"bool" : {
"must" : [ {
"text" : {
"content" : {
"query" : "404 get",
"type" : "phrase",
"operator" : "AND"
}
}
}, {
"terms" : {
"host" : [ "localhost" ]
}
} ]
}
}

I got no doc if doing the query with Java API but doing the query with
curl, some docs returned.

SearchResponse response = client.prepareSearch(getIndices())
                .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)

.setQuery(query).addFields(returnFields()).setFrom(from)
.setSize(size).execute().actionGet();

What's wrong with my java code?

Thanks,
Duy

It works. Thanks Vinicius.

On Tue, Jul 17, 2012 at 9:35 PM, Vinicius Carvalho <
viniciusccarvalho@gmail.com> wrote:

try this instead:

QueryBuilder query = boolQuery().must(textQuery("content", "404 get"
).type(Type.PHRASE).operator(Operator.AND)).should(termsQuery("host",
"localhost"));

SearchResponse response = client.prepareSearch(**getIndices())
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(query).addFields(

returnFields()).setFrom(from)
.setSize(size).execute().**actionGet();
Cheers

On Tuesday, July 17, 2012 6:41:40 AM UTC-4, Duy Do wrote:

Hi,

I'm very newbie to Elasticsearch. I use Java API to build the bool query
as following:

{
"bool" : {
"must" : [ {
"text" : {
"content" : {
"query" : "404 get",
"type" : "phrase",
"operator" : "AND"
}
}
}, {
"terms" : {
"host" : [ "localhost" ]
}
} ]
}
}

I got no doc if doing the query with Java API but doing the query with
curl, some docs returned.

SearchResponse response = client.prepareSearch(**getIndices())
                .setSearchType(SearchType.DFS_**QUERY_THEN_FETCH)
                .setQuery(query).addFields(**

returnFields()).setFrom(from)
.setSize(size).execute().**actionGet();

What's wrong with my java code?

Thanks,
Duy

--
Duy Do