Retrieve source document of a Hit with Java API

Hi,
I am just trying to do a simple search and retrieve the source document but
it looks like its having troubles finding a lucene class, is there anything
I am missing or doing wrong or is this a bug?

Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/lucene/document/FieldSelector
at
org.elasticsearch.search.internal.InternalSearchHit.sourceAsMap(InternalSearchHit.java:239)
at
org.elasticsearch.search.internal.InternalSearchHit.getSource(InternalSearchHit.java:208)
at test.Main.main(Main.java:42)
Caused by: java.lang.ClassNotFoundException:
org.apache.lucene.document.FieldSelector

    Client client = new TransportClient()
            .addTransportAddress(new 

InetSocketTransportAddress("host_name", 9300));

    TextQueryBuilder tqb1 = new TextQueryBuilder("pages.pageText", 

"text_to_find")
.type(TextQueryBuilder.Type.PHRASE);

    SearchResponse response = client.prepareSearch("index_name")
            .setSearchType(SearchType.QUERY_AND_FETCH)
            .setQuery(tqb1)
            .execute()
            .actionGet();
    for (SearchHit hit : response.getHits()){
        
        Map<String, Object> source = hit.getSource();
    }

Bad classpath.
Are you mixing Elasticsearch with Lucene dependencies ?

Check your project dependencies.

HTH
David :wink:
Twitter : @dadoonet / @elasticsearchfr

Le 23 juil. 2012 à 08:19, Dan_GTI danielszwed84@gmail.com a écrit :

Hi,
I am just trying to do a simple search and retrieve the source document but it looks like its having troubles finding a lucene class, is there anything I am missing or doing wrong or is this a bug?

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/document/FieldSelector
at org.elasticsearch.search.internal.InternalSearchHit.sourceAsMap(InternalSearchHit.java:239)
at org.elasticsearch.search.internal.InternalSearchHit.getSource(InternalSearchHit.java:208)
at test.Main.main(Main.java:42)
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.document.FieldSelector

    Client client = new TransportClient()
            .addTransportAddress(new InetSocketTransportAddress("host_name", 9300));

    TextQueryBuilder tqb1 = new TextQueryBuilder("pages.pageText", "text_to_find")
        .type(TextQueryBuilder.Type.PHRASE);

    SearchResponse response = client.prepareSearch("index_name")
            .setSearchType(SearchType.QUERY_AND_FETCH)
            .setQuery(tqb1)
            .execute()
            .actionGet();
    for (SearchHit hit : response.getHits()){
        
        Map<String, Object> source = hit.getSource();
    }

OK, was originally elasticsearch-0.19.8.jar went back to
using elasticsearch-0.19.0.jar and it started working fine...

On Monday, July 23, 2012 4:19:22 PM UTC+10, Dan-GTI wrote:

Hi,
I am just trying to do a simple search and retrieve the source document
but it looks like its having troubles finding a lucene class, is there
anything I am missing or doing wrong or is this a bug?

Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/lucene/document/FieldSelector
at
org.elasticsearch.search.internal.InternalSearchHit.sourceAsMap(InternalSearchHit.java:239)
at
org.elasticsearch.search.internal.InternalSearchHit.getSource(InternalSearchHit.java:208)
at test.Main.main(Main.java:42)
Caused by: java.lang.ClassNotFoundException:
org.apache.lucene.document.FieldSelector

    Client client = new TransportClient()
            .addTransportAddress(new 

InetSocketTransportAddress("host_name", 9300));

    TextQueryBuilder tqb1 = new TextQueryBuilder("pages.pageText", 

"text_to_find")
.type(TextQueryBuilder.Type.PHRASE);

    SearchResponse response = client.prepareSearch("index_name")
            .setSearchType(SearchType.QUERY_AND_FETCH)
            .setQuery(tqb1)
            .execute()
            .actionGet();
    for (SearchHit hit : response.getHits()){
        
        Map<String, Object> source = hit.getSource();
    }

ES 0.19.8 uses Lucene 3.6, while ES 0.19.0 uses Lucene 3.5, which
means you probably had Lucene 3.5 in your classpath while using
0.19.8.

On Sun, Jul 22, 2012 at 11:51 PM, Dan-GTI danielszwed84@gmail.com wrote:

OK, was originally elasticsearch-0.19.8.jar went back to using
elasticsearch-0.19.0.jar and it started working fine...

On Monday, July 23, 2012 4:19:22 PM UTC+10, Dan-GTI wrote:

Hi,
I am just trying to do a simple search and retrieve the source document
but it looks like its having troubles finding a lucene class, is there
anything I am missing or doing wrong or is this a bug?

Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/lucene/document/FieldSelector
at
org.elasticsearch.search.internal.InternalSearchHit.sourceAsMap(InternalSearchHit.java:239)
at
org.elasticsearch.search.internal.InternalSearchHit.getSource(InternalSearchHit.java:208)
at test.Main.main(Main.java:42)
Caused by: java.lang.ClassNotFoundException:
org.apache.lucene.document.FieldSelector

    Client client = new TransportClient()
            .addTransportAddress(new

InetSocketTransportAddress("host_name", 9300));

    TextQueryBuilder tqb1 = new TextQueryBuilder("pages.pageText",

"text_to_find")
.type(TextQueryBuilder.Type.PHRASE);

    SearchResponse response = client.prepareSearch("index_name")
            .setSearchType(SearchType.QUERY_AND_FETCH)
            .setQuery(tqb1)
            .execute()
            .actionGet();
    for (SearchHit hit : response.getHits()){

        Map<String, Object> source = hit.getSource();
    }