0

I am performing a search on a field that contains spaces, I would like it to not be analysed i.e. not be split to grams and be considered as a single entity. How do I do this in Java?

I am using the RESTHighLevelClient, version 7.4.

Ace
  • 700
  • 7
  • 37
  • The analisis is being done on the cluster, not in the java api. What is the type of the field in elasticsearch? You should check if keyword is the type for the field you are searching. – ibexit Dec 24 '19 at 22:05
  • @ibexit The field is a string field, the data contains spaces. Initial loading of the records into the elasticsearch instance is done by the same java application. The Keyword I am searching also can contain the spaces to match the field data. How can I do this? – Ace Dec 30 '19 at 15:46

1 Answers1

0

String is the datatype you are using in your java application. But in elasticsearch there are serveral string based field datatypes.

You should define a mapping for the documents you want to store in elasticsearch. For the field we're talking about, choose the keyword dataype in your mapping. Please be aware, that you cannot change the mapping of a field after documents with such one has been indexed. So try creating a new index and put the desired mapping using the mapping rest api for example. Afterwards, not earlier, index your data.

If you don't do that before indexing your documents, elasticsearch will guess the datatype for a field based on the values provided by the first document containing the field. Probably thats why your applications java string has been mapped to the text datatype in elasticsearch and searching on text differs form searches on a keyword field.

Cheers & happy new year!

ibexit
  • 3,465
  • 1
  • 11
  • 25
  • "Love Peace Rock" is the data for the field, the search string expected is "Love Peace". This doesn't return me the data. If I replace the space with "_" I get the data. – Ace Jan 02 '20 at 13:03
  • Please be so kind and execute the following request in your elasticsearch instance, then provide me with the response: GET index-name/_mapping (https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html) – ibexit Jan 03 '20 at 16:25