obtain field names

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
nmz
Reply | Threaded
Open this post in threaded view
|

obtain field names

nmz
Hi,

 Is it possible to obtain the 'field names'[not values] of the indexed
document using java API in elastic search?
Reply | Threaded
Open this post in threaded view
|

Re: obtain field names

dadoonet
IMHO

You could get the mapping of your document type.
You can get your document as a Map and find field names as keys

Does it help ?

David ;-)
Twitter : @dadoonet / @elasticsearchfr

Le 2 mai 2012 à 11:11, nmz <[hidden email]> a écrit :

> Hi,
>
> Is it possible to obtain the 'field names'[not values] of the indexed
> document using java API in elastic search?
nmz
Reply | Threaded
Open this post in threaded view
|

Re: obtain field names

nmz
Hi,

Thanks for the reply.

I tried the following code:

 ClusterState cs =
client.admin().cluster().prepareState().execute().actionGet().getState();
 IndexMetaData imd = cs.getMetaData().index(INDEX_NAME);
 MappingMetaData mmd = imd.mapping(DOCUMENT_NAME);
 Map<String, Object> source = mmd.sourceAsMap();

source.keySet()  -- only has the value 'properties'
source.values() -- has the remaining part of the document mapping.

So do I have to parse the values() and extract the 'field names' or is
there any other way to obtain the it.

Correct me if my approach is wrong.

On May 2, 2:17 pm, David Pilato <[hidden email]> wrote:

> IMHO
>
> You could get the mapping of your document type.
> You can get your document as a Map and find field names as keys
>
> Does it help ?
>
> David ;-)
> Twitter : @dadoonet / @elasticsearchfr
>
> Le 2 mai 2012 à 11:11, nmz <[hidden email]> a écrit :
>
>
>
>
>
>
>
> > Hi,
>
> > Is it possible to obtain the 'field names'[not values] of the indexed
> > document using java API in elastic search?
Reply | Threaded
Open this post in threaded view
|

Re: obtain field names

kimchy
Administrator
You will need to navigate through the map, or parse the source (using jackson for example) in order to aggregate all the field names.

On Wed, May 2, 2012 at 1:45 PM, nmz <[hidden email]> wrote:
Hi,

Thanks for the reply.

I tried the following code:

 ClusterState cs =
client.admin().cluster().prepareState().execute().actionGet().getState();
 IndexMetaData imd = cs.getMetaData().index(INDEX_NAME);
 MappingMetaData mmd = imd.mapping(DOCUMENT_NAME);
 Map<String, Object> source = mmd.sourceAsMap();

source.keySet()  -- only has the value 'properties'
source.values() -- has the remaining part of the document mapping.

So do I have to parse the values() and extract the 'field names' or is
there any other way to obtain the it.

Correct me if my approach is wrong.

On May 2, 2:17 pm, David Pilato <[hidden email]> wrote:
> IMHO
>
> You could get the mapping of your document type.
> You can get your document as a Map and find field names as keys
>
> Does it help ?
>
> David ;-)
> Twitter : @dadoonet / @elasticsearchfr
>
> Le 2 mai 2012 à 11:11, nmz <[hidden email]> a écrit :
>
>
>
>
>
>
>
> > Hi,
>
> > Is it possible to obtain the 'field names'[not values] of the indexed
> > document using java API in elastic search?

Reply | Threaded
Open this post in threaded view
|

Re: obtain field names

nithy1
This post has NOT been accepted by the mailing list yet.
This is a solution and a question.

How about using index templates? In my case, I have used index template for creating my index. Therefore, I can get the template mapping and the field names from that using angular, jquery api. In response, you can use use dot and path upto properties and then use javascript's Object.keys() to get the fields list. No matter if the indices are dropped or changed, the index template (if you solution design uses it, will get you changed / new fields list). However, the same is not possible with java api. Is there, get template option in java api?