We have indexed all the records from our table to ES.
After that we are searching for some fields on indexed records.
Here is the code snippet for indexing....
for (final Contact contact : contacts) {
final XContentBuilder builder =
XContentFactory.jsonBuilder()
.startObject();
builder.field("CONTACT_ID", contact.getId());
final Map<String, Object> attributes =
contact.getAttributes();
for (final String fieldName : attributes.keySet()) {
builder.field(fieldName,
attributes.get(fieldName));
}
builder.endObject();
final IndexRequestBuilder prepareIndex =
client.prepareIndex(
indexName, type,
StringUtils.lowerCase(String.valueOf(contact.getId())));
prepareIndex.setSource(builder);
bulkRequest.add(prepareIndex);
}
BulkResponse bulkResponse = bulkRequest.execute().actionGet();
While indexing we haven't used any analyzers. What is the default analyzer
it uses if we don't specify any thing ?
If we wanted to use which is best Analyzer to use , I mean Keyword or
standard and how to use that analyzer using java api while indexing ?
Here is the code snippet to search for multiple fields on ES data...
we will get a list of search fields from upper layer to ES layer
SearchAttribute {
private String attributeName;
private String attributeValue;
setters & getters
}
from list of searchAttributes we are building query like...
for(SearchAttributeDo searchAttribute : searchAttributes){
boolQueryBuilder.should(QueryBuilders.termQuery(searchAttribute.getAttributeName(),
searchAttribute.getAttributeValue()));
}
SearchRequestBuilder srb = client.prepareSearch()
.setTypes(repoName)
.setQuery(boolQueryBuilder);
SearchResponse searchResponse = srb.execute().actionGet();
One strange thing we observed was when we give the attribute value in lower
case then only it returning results, otherwise it is not returning results.
For example if the "Lawrence" is indexed as FIELD_NAME but while querying
if we give "Lawrence" we are not getting any results. But when we give as
"lawrence" we are getting response back.
I think that might be because lucene is internally converting everything in
to lower case while indexing.
Please can you suggest us in following things...
-
what is best analyzers to use while indexing and searching ...
we have values to be indexed and searched like... TELE_PHONE
-->"510/782-1117" & EMAIL -- >"elasticquery@help.com" -
Is the way which we followed to search on multiple fields with each
field with it's own value ? Or could you suggest any other better way ? we
used bool query for that by iterating through list of search attribute
objects.
Thanks,
Navvi.
--