Java API Highlighting

I'm new to Elasticsearch and I have two questions. I've done quite a bit of
Google searching and looked at the Elasticsearch tests for guidance, but
I'm not getting the desired result.

I'm querying an Elasticsearch server I don't control, but the index seems
straight forward enough. When I query it via the Java API however, I cannot
get highlights to work. My code looks more or less like this:

SearchRequestBuilder builder = client.prepareSearch(SEARCH_INDEX)
.setTypes(SEARCH_DOCUMENT_TYPE)
.setSearchType(SearchType.QUERY_AND_FETCH)
.addHighlightedField("content")
.addHighlightedField("title")
.addHighlightedField("subject")
.addAggregation(AggregationBuilders.terms("types-count").field("type"))
.setQuery(QueryBuilders.simpleQueryString(query))
.setQuery(QueryBuilders.queryString(query)).execute().actionGet();

I get back results, but I don't get back a "highlight" collection. I get
back this instead:

"highlightFields": {
"content": {
"name": "content",
"fragments": [
{},
{}
]
},
"title": {
"name": "title",
"fragments": [
{}
]
}
}

In other words, it seems like it wanted to find fragments, but it gave me
blank results. Thinking maybe it was something wrong with the index, I
POSTed this to the server:

{ "highlight" : { "fields" : { "content" : {} }
}
, "fields": ["title", "_id", "subject", "uri", "dateEffective"]
}

And got the expected results:

"highlight": {
"content": [
" fuel transfer pump operation,
\r\ninstall Javelin Placard 782-14 or an equivalent FAA-approved
placard",
"73-17-01 CESSNA: Amdt. 39-1701.
Applies to all series of Cessna Models 170, \r\n172, 175, 180 and"
,
", adjacent \r\nto the fuel transfer pump
switch which reads as follows: "AUXILIARY FUEL \r\nTRANSFER PUMP",
". PULL ON. PUSH OFF. PLACE PUMP OFF
BEFORE CHANGING FROM LEFT \r\nTANK." \r\n\r\n\tNOTE: Failure to turn",
" off fuel boost pump allows air to enter
engine \r\nfuel system and may cause engine power failure when"
]
}

It's obvious I'm doing something wrong in the API, but I can't seem to get
it to perform the highlighting I want. Any help?

This leads me to my second question. When trying to debug this, I wanted to
view the "source" or JSON of the request being sent to Elasticsearch so I
could compare but I couldn't find a method for this. I resorted to sniffing
my traffic with Wireshark, but it was not very efficient for viewing what I
was sending to the server.

Is there a log level or something I can set in the Java API?

Thanks!

--
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/50112bd3-6d3e-4c23-998c-6a609cfdbf7d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

You have probably found an answer to your question. But it seems there is little here about examples for the java API and highlighting.

I recently found this page, maybe it helps you with another way of doing things?
http://www.programcreek.com/java-api-examples/index.php?api=org.elasticsearch.search.highlight.HighlightField