Return specific field and highlights via Java API

I am having two issues using the java api

  1. I am not able to return specific field in my search query - It shows I
    have the right number of results, but displays Null
  2. Not return highlights
    Note: Assume Indexing is fine, because I am able to get correct results if
    comment out the line .AddField("hid")
    I am using default everything, I understand for highlights _source for
    field has to be enabled, but I thought if not, it grabs the original source.

json:
{"uid":'123", "name":"hello},
{"uid":'1234", "name":"hello1}

node = NodeBuilder.nodeBuilder() //

            .local(true)//

            .data(true) //

            .node();

            client = node.client();

//..createIndex

private void search(String index, String type,String field, String value)

  {

          SearchResponse response = client.prepareSearch(index)

                      

          .setTypes(type)

         .addHighlightedField("uid")

         .addField("uid")

         SearchHit[] results = response.getHits().getHits();


            System.out.println("Current results: " + results.length);

          for (SearchHit hit : results) {

            System.out.println("------------------------------");

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

             System.out.println(result);

        }


    }

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/4984505f-9946-4855-8bf0-5dd11b0a1b21%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

A couple of things:

  1. If you ask for any fields, you must also ask for source or else you
    won't get the source. You get the source by default only if you don't ask
    for any fields. At least, that's the behavior I've seen.

  2. If you ask for the "hid" field, then I am guessing you need to set
    "store":true or something like that in the mapping.

Other than that, I am also interesting in some examples of highlighting via
the Java API!

Brian

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/4c6e3d8b-e178-4976-ad4e-65bc6f7d6d00%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.