1

When I Indexed data and then Searched data in one Thread(Process) It works . If I Indexed and stop the process then run only searching to find indexed data, no hits. What is the reason of this propblem or what is my mistake client or something ? I am new at Elastic Search, so I cant find the reason Please Help me.

    org.elasticsearch.node.Node node = nodeBuilder().clusterName("farukest").node();
    Client client = node.client();

        String[] deneme = {keyword[0]}; // keyword fetched from database
        for (int i = 0; i < degerler.length; i++) {

            IndexResponse response = client.prepareIndex("Ali9".toLowerCase(),"Api",Integer.toString(i))
                    .setSource(jsonBuilder()
                            .startObject()
                            .field("Post Id", degerler[i][0].toString())
                            .field("Post Like Count", degerler[i][1].toString())
                            .field("Post Shares Count", degerler[i][2].toString())
                            .field("Post Comment Count", degerler[i][3].toString())
                            .field("Page Name",degerler[i][4].toString())
                            .field("Message", degerler[i][5].toString())
                            .endObject()
                    ).setRefresh(true)
                    .execute()
                    .actionGet();

       SearchResponse r = client.prepareSearch("Ali9".toLowerCase()) // Searching
                    .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
                    .setQuery(termQuery("Message", "Fenerbahçelim".toLowerCase()))
                    .setFrom(0).setSize(60).setExplain(true)
                    .execute()
                    .actionGet();
                        System.out.println(r);
            SearchHit[] hits = r.getHits().getHits();
            System.out.println(hits.length);
            for (SearchHit searchHit : hits) {
            Map<String, Object> source = searchHit.getSource();
                for (Map.Entry<String,Object> values : source.entrySet()) {
                    System.out.println(values.getValue()+"  ...");
                }
            }  

If I run seperately, Result is 0 Data. If I run these in one process it works.

  • Are you spinning up and destroying a node each time, or are you connecting to a real ES instance? If its a fake/cluster and node do you need different settings (gateway maybe..) to make it persistent between jvms? – mconlin Jan 28 '14 at 21:51
  • I followed the Elastic Search guide.I didnt understand what you said destroying a node,you mean node.close()? I added JAVA_HOME to Computer->Adv.Settings->Environment Variables and run ElasticSearch->elasticsearch-service-x64.exe then run as administrator elasticsearch.bat . When i did these settings I wrote localost:9200 some information showed up.but after a while I tried localhost:9200 it didnt work.I think my client node or something settings wrong. Now I tried something.I indexed data and when process finished.I run Searching process qucikly,hit 1 showed.But after 5 second 0 hit again. – user3077045 Jan 28 '14 at 22:17
  • I waited 20 minute then run only searching ,it works correctly, giving Hits.But in some trials giving 0 hit.How is it possible ? Please help me i have to fix this. – user3077045 Jan 28 '14 at 23:08

0 Answers0