2
  • I'm working on the elasticsearch version 7.2 and i'm in the
    process of improving the performance of ES calls made by the
    application.
  • From what I read, if we haven't set a "search analyzer" , by default standard analyzer will be set.
  • But in a case where a analyzer is not needed ,having an analyzer may affect performance. Do having all fields as "keywords" prevents this?
  • Or is there any other way to disable this "search analyzer"

Ps: For any answer if you could point me to the ES official documentation of which the answer is based on , I"ll really appreciate.

Asiri Liyana Arachchi
  • 2,663
  • 5
  • 24
  • 43

1 Answers1

3

There are various scenarios where search analyzers come into the picture.

Type of query:- Some queries are analyzed and some are not. queries which are analyzed like match query uses the same analyzer on the fields which were defined in the index mapping, while queries like term query don't use any search time analyzer. Read elasticsearch match vs term query

Also snippet from official ES doc

The match query is of type boolean. It means that the text provided is analyzed and the analysis process constructs a boolean query from the provided text.

Type of fields:

Text fields are analyzed by default and standard analyzer is the default analyzer for them, hence if you don't define an analyzer for text fields in index mapping and then make a match query, it would use the standard analyzer but if you use the term query then it would not use the search time analyzer.

keyword fields then it would use the keyword analyzer, which is no-op analyzer, hence for match query on keyword fields it would use the keyword analyzer but is essentially like applying no search time analyzer.

If you are using the match query or any other analyzed query, which uses the search time analyzers, then you can explicitly mention the search time analyzer as a keyword analyzer, which as I explained is a no-op analyzer, hence process of generating the tokens would be very efficient.

Amit
  • 30,756
  • 6
  • 57
  • 88
  • 1
    @Asiri I would like to add that though disabling analyzer might help you improve performance only if there is no use case of full text search. If there are or in near future you feel there will be use case for full text search then you might not to able to implement that. – Nishant Jun 28 '19 at 03:58
  • I'm using match queries ( Actually i want them to be term queries on filter context but spring elastic search data findByParameter1AndParameter2 in repository seems to use match query on query context) but all the fields in my index are keywords. So by your explanation it means there is no search analyzer happening when I make ES calls. – Asiri Liyana Arachchi Jun 28 '19 at 03:59
  • @NishantSaini I'm using keyword for all the fields. So seems like I don't need to explicitly specify disabling of analyzers or changes the query type to term. Am i right? The calls to ES in my case are already performant in terms of "search analyzer" ? – Asiri Liyana Arachchi Jun 28 '19 at 04:05
  • 1
    @AsiriLiyanaArachchi, if you are using keyword fields, then even if you use match query, it's not going through the costly analysis process https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis.html and yes, in this case, you don't have to explicitly define search analyzer and it's already performant – Amit Jun 28 '19 at 04:08
  • 1
    @AsiriLiyanaArachchi, yeah but please consider the point given by Nishant in case of text fields as changing analyzer is a breaking change and would require reindexing. – Amit Jun 28 '19 at 04:09
  • Also worth thinking that if no analyzer is needed at search time, why going through the troubles of analyzing the data at indexing time at all? That's a waste of performance and resources. – Val Jun 28 '19 at 04:57