I am using ElasticSearch Java API for search. I have four fields:
- key
- name
- DOB
- address
While searching I am using following query:
QueryBuilder qb =QueryBuilders.queryString("Pritish");
This is including key while searching. Also, I do not want to select fileds as:
.fields("DOB", "name", "address")
Is there any way to exclude field? I was looking for ParitalFields. Is it useful for my case? Can some one help to provide java example for this?
Now, I have added mapping as follows:
/***************************** Create Index ******************************/
XContentBuilder mapping = jsonBuilder()
.startObject()
.startObject(indexName)
.startObject("properties")
.startObject("key")
.field("type", "string")
.field("index","not_analyzed")
.field("store", "false")
.endObject()
.startObject("addr1")
.field("type","string")
.endObject()
.startObject("DOB")
.field("type","string")
.endObject()
.startObject("name")
.field("type","string")
.endObject()
.endObject()
.endObject()
.endObject();
client.admin()
.indices()
.preparePutMapping(indexName)
.setType(indexName)
.setSource(mapping)
.execute()
.actionGet();
/********************** Insert Data *****************************/
XContentBuilder x = jsonBuilder()
.startObject()
.field("key", key)
.field("addr1", "abc road")
.field("DOB", "09092009")
.field("name","test")
.endObject();
bulk.add(client.prepareIndex(indexName, indexName).setSource(x));
/************* Search Query **********************/
QueryBuilder qb =QueryBuilders.queryString("*e434*");
SearchResponse response = client.prepareSearch(indexName)
.setQuery(qb)
.setFrom(0)
.setSize(100)
.execute()
.actionGet();
SearchHit[] results = response.getHits().hits();
When, I see the index meta data, it is showing me proper mapping as follows:
mappings: {
indexName: {
properties: {
addr1: {
type: string
}
name: {
type: string
}
key: {
index: not_analyzed
type: string
}
acct_type: {
type: string
}
}
}
}
Now, when I perform search query, it is still showing me the result which search against the key.
I am not sure what's going wrong. Can anybody please help to resolve this?