How to retrieving all fields with Java client?


(Yuhan) #1

Hi all,

In case receiving a certain fields from a doc, I could construct query in
this way:

        SearchRequestBuilder searchBuilder = client.prepareSearch(

indexName, indexType )
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery( builder )
.addField(field)
.setFrom(0).setSize( urls.length );

I'm trying to perform a search query on an index with all the fields
returned without explicitly specifying them.
however, if I left without "addField", it returns docs without any fields.

is there a way I could retrieve this with ES java client?

Thank you.

Yuhan


(Ivan Brusic) #2

You can use wildcards in the field name: .addField("*")

Alternatively, if you have source enabled (the default), you can
extract the fields from the source: SearchHit#getSource().

Cheers,

Ivan

On Mon, Jul 30, 2012 at 5:10 PM, Yuhan Zhang yzhang@onescreen.com wrote:

Hi all,

In case receiving a certain fields from a doc, I could construct query in
this way:

        SearchRequestBuilder searchBuilder = client.prepareSearch(

indexName, indexType )
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery( builder )
.addField(field)
.setFrom(0).setSize( urls.length );

I'm trying to perform a search query on an index with all the fields
returned without explicitly specifying them.
however, if I left without "addField", it returns docs without any fields.

is there a way I could retrieve this with ES java client?

Thank you.

Yuhan


(Yuhan) #3

Hi Ivan,

.addField("*") didn't work in my case, It returns me 0 with
searchResponse.getHits().getHits()[0].getFields().values().size() ...

I tried to get the source but received null from
response.getHits().getHits()[0].getSource()

I'm wondering what I did wrong... I'm using the 0.19.4 client.

Thank you.

Yuhan

On Mon, Jul 30, 2012 at 5:13 PM, Ivan Brusic ivan@brusic.com wrote:

You can use wildcards in the field name: .addField("*")

Alternatively, if you have source enabled (the default), you can
extract the fields from the source: SearchHit#getSource().

Cheers,

Ivan

On Mon, Jul 30, 2012 at 5:10 PM, Yuhan Zhang yzhang@onescreen.com wrote:

Hi all,

In case receiving a certain fields from a doc, I could construct query in
this way:

        SearchRequestBuilder searchBuilder = client.prepareSearch(

indexName, indexType )
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery( builder )
.addField(field)
.setFrom(0).setSize( urls.length );

I'm trying to perform a search query on an index with all the fields
returned without explicitly specifying them.
however, if I left without "addField", it returns docs without any
fields.

is there a way I could retrieve this with ES java client?

Thank you.

Yuhan

--
Yuhan Zhang
Senior Software Engineer
OneScreen Inc.
yzhang@onescreen.com ehorne@onescreen.com
www.onescreen.com
(949) 525-4825 Ext: 177

The information contained in this e-mail is for the exclusive use of the
intended recipient(s) and may be confidential, proprietary, and/or legally
privileged. Inadvertent disclosure of this message does not constitute a
waiver of any privilege. If you receive this message in error, please do
not directly or indirectly print, copy, retransmit, disseminate, or
otherwise use the information. In addition, please delete this e-mail and
all copies and notify the sender.


(vkaggal) #4

Hello, I am wondering if you ever solved this issue?

I am using elasticsearch-0.19.9 and the following still does not work?

SearchRequestBuilder builder = client.prepareSearch("idx1002")
.setSearchType(SearchType.DEFAULT)
.setQuery(qb1).addField("*");

Example:
{
a:{
b: { attr: "value" }
}
}

IF I need to retrieve the field "attr" in the resulting documents, should I be adding a.b.attr via .addField("a.b.attr")?

Any help to retrieve specific field that is nested (example above) would be appreciated.

Thanks.


(Vinod-2) #5

Have you had any luck in retrieving the fields?

On Monday, July 30, 2012 7:10:24 PM UTC-5, Yuhan wrote:

Hi all,

In case receiving a certain fields from a doc, I could construct query in
this way:

        SearchRequestBuilder searchBuilder = client.prepareSearch( 

indexName, indexType )
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery( builder )
.addField(field)
.setFrom(0).setSize( urls.length );

I'm trying to perform a search query on an index with all the fields
returned without explicitly specifying them.
however, if I left without "addField", it returns docs without any fields.

is there a way I could retrieve this with ES java client?

Thank you.

Yuhan

--


(Yuhan) #6

Hi Vinod,

the field names of an index can be read from its mapping :slight_smile:

http://localhost:9200/my_index/_mapping?pretty=1
http://localhost:9200/my_index/my_type/_mapping?pretty=1

Yuhan

On Fri, Oct 12, 2012 at 9:26 AM, Vinod vkaggal@gmail.com wrote:

Have you had any luck in retrieving the fields?

On Monday, July 30, 2012 7:10:24 PM UTC-5, Yuhan wrote:

Hi all,

In case receiving a certain fields from a doc, I could construct query in
this way:

        SearchRequestBuilder searchBuilder = client.prepareSearch(

indexName, indexType )
.setSearchType(SearchType.DFS_**QUERY_THEN_FETCH)
.setQuery( builder )
.addField(field)
.setFrom(0).setSize( urls.length );

I'm trying to perform a search query on an index with all the fields
returned without explicitly specifying them.
however, if I left without "addField", it returns docs without any fields.

is there a way I could retrieve this with ES java client?

Thank you.

Yuhan

--

--
Yuhan Zhang
Senior Software Engineer
OneScreen Inc.
yzhang@onescreen.com ehorne@onescreen.com
www.onescreen.com
(949) 525-4825 Ext: 177

The information contained in this e-mail is for the exclusive use of the
intended recipient(s) and may be confidential, proprietary, and/or legally
privileged. Inadvertent disclosure of this message does not constitute a
waiver of any privilege. If you receive this message in error, please do
not directly or indirectly print, copy, retransmit, disseminate, or
otherwise use the information. In addition, please delete this e-mail and
all copies and notify the sender.

--


(vkaggal) #7

Thank you Yuhan. I will used the _mapping before, however, I was wondering
if there was some way to do this using Java API.

Thanks.

On Tue, Oct 16, 2012 at 1:07 PM, Yuhan [via ElasticSearch Users] <
ml-node+s115913n4024090h58@n3.nabble.com> wrote:

Hi Vinod,

the field names of an index can be read from its mapping :slight_smile:

http://localhost:9200/my_index/_mapping?pretty=1
http://localhost:9200/my_index/my_type/_mapping?pretty=1

Yuhan

On Fri, Oct 12, 2012 at 9:26 AM, Vinod <[hidden email]http://user/SendEmail.jtp?type=node&node=4024090&i=0

wrote:

Have you had any luck in retrieving the fields?

On Monday, July 30, 2012 7:10:24 PM UTC-5, Yuhan wrote:

Hi all,

In case receiving a certain fields from a doc, I could construct query
in this way:

        SearchRequestBuilder searchBuilder = client.prepareSearch(

indexName, indexType )
.setSearchType(SearchType.DFS_**QUERY_THEN_FETCH)
.setQuery( builder )
.addField(field)
.setFrom(0).setSize( urls.length );

I'm trying to perform a search query on an index with all the fields
returned without explicitly specifying them.
however, if I left without "addField", it returns docs without any
fields.

is there a way I could retrieve this with ES java client?

Thank you.

Yuhan

--

--
Yuhan Zhang
Senior Software Engineer
OneScreen Inc.
[hidden email] http://user/SendEmail.jtp?type=node&node=4024090&i=1

www.onescreen.com
(949) 525-4825 Ext: 177

The information contained in this e-mail is for the exclusive use of the
intended recipient(s) and may be confidential, proprietary, and/or legally
privileged. Inadvertent disclosure of this message does not constitute a
waiver of any privilege. If you receive this message in error, please do
not directly or indirectly print, copy, retransmit, disseminate, or
otherwise use the information. In addition, please delete this e-mail and
all copies and notify the sender.

--


If you reply to this email, your message will be added to the discussion
below:

http://elasticsearch-users.115913.n3.nabble.com/how-to-retrieving-all-fields-with-Java-client-tp4021061p4024090.html
To unsubscribe from how to retrieving all fields with Java client?, click
herehttp://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4021061&code=dmthZ2dhbEBob3RtYWlsLmNvbXw0MDIxMDYxfDIwMzI4OTI0OTQ=
.
NAMLhttp://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html!nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers!nabble%3Aemail.naml-instant_emails!nabble%3Aemail.naml-send_instant_email!nabble%3Aemail.naml

--
Vinod C K
ವಿನೋದ್ ಸಿ ಕೆ


(system) #8