Java API search returns no results... (JUnit test)


(stelios) #1

Hi,

I'm using Java API in a JUnit test to evaluate elasticsearch.
Problem is I can't get any search results...

getting document by id works fine but I see that the fields are not populated...even after explicitly mapping
one the fields.
is this the reason why I get totalHits=0? wrong mapping?

I can post the code if needed.

thanks
stelios

P.S. I'm using 0.14.2 version


(stelios) #2

OK I don't get results since I don't have fields.

Is this the correct way of mapping the document I've indexed?


XContentBuilder data = XContentFactory.jsonBuilder()
.startObject().startObject("properties")
.startObject("name")
.field("type", "string")
.field("index", "not_analyzed")
.field("store", "yes")
.endObject()
.endObject().endObject();

    CreateIndexResponse mapping = client.admin().indices().create(
            createIndexRequest("resource").mapping("file", data)
    ).actionGet();

and he is the indexed document

IndexResponse resp = client.prepareIndex("resource", "file", "1")
.setSource(builder.startObject()
.field("name", "findMe")
.field("postDate", new Date())
.field("message", "trying out Elastic Search")
.endObject())
.execute().actionGet();

Thanks
Stelios


(stelios) #3

Problem was how I created the mapping, jsonBuilder...
creating it as a string and putting it the same way works fine...


(Shay Banon) #4

Hard to tell, if you can gist your simple test class, I can have a look.
On Thursday, February 3, 2011 at 2:35 PM, stelios wrote:

Hi,

I'm using Java API in a JUnit test to evaluate elasticsearch.
Problem is I can't get any search results...

getting document by id works fine but I see that the fields are not
populated...even after explicitly mapping
one the fields.
is this the reason why I get totalHits=0? wrong mapping?

I can post the code if needed.

thanks
stelios

P.S. I'm using 0.14.2 version

--
View this message in context: http://elasticsearch-users.115913.n3.nabble.com/Java-API-search-returns-no-results-JUnit-test-tp2413072p2413072.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


(stelios) #5

yeah I had a wrong mapping there...
Results are fine now

thanks
stelios

On 7 February 2011 19:05, kimchy [via ElasticSearch Users] <
ml-node+2445435-1952517049-341730@n3.nabble.com> wrote:

Hard to tell, if you can gist your simple test class, I can have a look.

On Thursday, February 3, 2011 at 2:35 PM, stelios wrote:

Hi,

I'm using Java API in a JUnit test to evaluate elasticsearch.
Problem is I can't get any search results...

getting document by id works fine but I see that the fields are not
populated...even after explicitly mapping
one the fields.
is this the reason why I get totalHits=0? wrong mapping?

I can post the code if needed.

thanks
stelios

P.S. I'm using 0.14.2 version

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Java-API-search-returns-no-results-JUnit-test-tp2413072p2413072.htmlhttp://elasticsearch-users.115913.n3.nabble.com/Java-API-search-returns-no-results-JUnit-test-tp2413072p2413072.html?by-user=t
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


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

http://elasticsearch-users.115913.n3.nabble.com/Java-API-search-returns-no-results-JUnit-test-tp2413072p2445435.html
To unsubscribe from Java API search returns no results... (JUnit test), click
herehttp://elasticsearch-users.115913.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=2413072&code=c3RldG9naWFzQGdtYWlsLmNvbXwyNDEzMDcyfC0xMDc4NTcwNTM2.


(system) #6