Created
May 30, 2014 08:16
-
-
Save mchv/492efc68e06dc4f2a18c to your computer and use it in GitHub Desktop.
Elasticsearch Terms Vector API example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.elasticsearch.action.ActionListener | |
import org.elasticsearch.action.termvector.TermVectorResponse | |
import org.elasticsearch.action.termvector.TermVectorRequestBuilder | |
import org.elasticsearch.common.xcontent.ToXContent | |
import org.elasticsearch.common.xcontent.XContentBuilder | |
import org.elasticsearch.common.xcontent.XContentFactory | |
import org.elasticsearch.common.xcontent.XContentType | |
def getTermsVector(`type`: String, id: String, field: String) { | |
val builder = new TermVectorRequestBuilder(client, index, `type`, id).setSelectedFields(field) | |
builder.setTermStatistics(true).setFieldStatistics(true) | |
builder.execute(new ActionListener[TermVectorResponse] { | |
def onResponse(response: TermVectorResponse) { | |
val builder = XContentFactory.contentBuilder(XContentType.JSON).prettyPrint() | |
response.toXContent(builder, ToXContent.EMPTY_PARAMS) | |
println("TermsVector: " + builder.string) | |
} | |
def onFailure(e: Throwable) {e.printStackTrace} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment