Hello everyone,
well i am new to Elasticsearch and i am facing some similar difficulties
as mentioned above. i tried implementing some of the suggested solution but
to no avail.
I am posting part of codes and will be very grateful if somebody could help
me out. Thanks in advance.
the codes are written in java:
// i have the following in the mapping part
CreateIndexRequestBuilder builder =
client.admin().indices().prepareCreate(index)
.setSettings(ImmutableSettings.settingsBuilder().loadFromSource(configIndex));
builder.addMapping("StatTest", "{\n" +
" \"StatTest\" : {\n" +
" \"_all\" : { \n" +
" \"analyzer\":\"francais\" \n" +
" },\n" +
" \"properties\" : {\n" +
" \"idUser\" : {\"type\" : \"string\",
"analyzer":"francais"},\n" +
" "loginOfUser" : {"type" : "string",
"analyzer":"francais"},\n" +
" "nameOfUser" : {"type" : "string",
"analyzer":"francais"},\n" +
" }\n" +
" }\n" +
"}");
//the sample data stored are the following
{idUser: "0121", loginOfUser: "login0121", nameOfUser :"mona lisa"},
{idUser: "0122", loginOfUser: "login0122", nameOfUser :"James Dean"},
//i am trying to get facets based upon name of user
//TermsFacetBuilder fb =
FacetBuilders.termsFacet("idOfUser").field("loginOfUser");
TermsFacetBuilder fb =
FacetBuilders.termsFacet("idOfUser").field("nameOfUser");
SearchRequestBuilder srb1 =
client.prepareSearch().setIndices(index).addFacet(fb);
AndFilterBuilder myFilters = FilterBuilders.andFilter();
myFilters.add(FilterBuilders.termFilter("year", "2014"));
FilterBuilder fbBuilder = FilterBuilders.andFilter(myFilters);
FilteredQueryBuilder q =
QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),fbBuilder);
SearchResponse sr = srb1.setQuery(q).execute().actionGet();
TermsFacet f = (TermsFacet)
sr.getFacets().facetsAsMap().get("idOfUser");
for (TermsFacet.Entry entry : f) {
String type = entry.getTerm().toString();
//System.out.println("....enter type : "+type);
//System.out.println("....enter entry.getCount() :
"+entry.getCount());
}
//problems faced whenever i am trying to do a facet based on login of user,
everything works well
the variable type returns :
login0121
login0122
however when i try to do a facet based on nameOfUser , the following is
returned:
mona
lisa
James
Dean
/////
i want to retriev the usernames as one token only,
am i missing some codes somewhere
i will be very thankful if any one can help me on this
thanks in advance
On Wednesday, 24 August 2011 22:36:02 UTC+4, ogregras wrote:
Thanks kimchy!
--
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/a5cc7038-01d1-4a8e-ab7a-5f84d51e0296%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.