Should not analyze the data while indexing and searching


(Sanjay Reddy) #1

Hi,
I have an issue regarding Elasticsearch Indexing and searching.
I'm trying to index data to elasticsearch using java. After indexing I have observed that it is taking "Kenneth Cole" as "Kenneth" and "Cole".

This is happening while searching the data from elasticsearch also. If I search for "Kenneth Cole", it is searching for "Kenneth" OR "Cole". I'm using the following code.

public class elastic {

	public static void main(String[] args) throws IOException {
		Client client = new TransportClient().addTransportAddress(new InetSocketTransportAddress("localhost", 9300));

		BulkRequestBuilder bulkRequest = client.prepareBulk();
		bulkRequest.add(client.prepareIndex("twitter", "tweet", "1")
		        .setSource(jsonBuilder()
		                    .startObject()
		                        .field("user", "kimchy")
		                        .field("postDate", new Date())
		                        .field("message", "trying out Elasticsearch")
		                    .endObject()
		                  )
		        );
		bulkRequest.add(client.prepareIndex("twitter", "tweet", "3")
		        .setSource(jsonBuilder()
		                    .startObject()
		                        .field("user", "kimchy")
		                        .field("postDate", new Date())
		                        .field("message", "another post")
		                    .endObject()
		                  )  );	
		BulkResponse bulkResponse = bulkRequest.get();
        }

Please help me in getting out of this issue.

Thanks & Regards,
Sanjay Reddy.


(David Pilato) #2

This is expected. This is how analysis process works.

You should read this chapter: https://www.elastic.co/guide/en/elasticsearch/guide/current/mapping-analysis.html


(system) #3