Where should I add Analyzer?

Hi,

I'm a beginner and I want to use some analyzer in my code to add synonym and to eliminate stopwords but I don't know where I must add it exactly ! (after first query ? or after second query ? ...)

my code look like that :

processArrFn['basket'] = (nomCallback) =>

    client.search
      index: 'gosport'
      type: 'objbasket'
      size: @_SEARCH_SIZE
      body: 
        query:
          function_score:
            query:
              query_string:
                fields: ["NAME^5", "TYPE^1", "DEFINITION^3"]
                query: queryTxt
            boost_mode: "multiply"
    .then (res) => nomCallback(null, res)

Thank you !

Hi,

Analyzers are typically already used for the first time when you are indexing your document, e.g. for stopword removal. So adding them only in your query doesn't work. You need to specify them in your field mappings that you can customize. The whole process and how mappings and analyzers are related is described in its own chapter in the ES Definitive Guide.

1 Like

in what i know ( i know ) have 2 way analyzer.
type 1 : analyzer when you index data to elasticsearch
type 2 : analyzer when you search (analyzer keyword)

Can you explain what you want search in 2 type ?. i cant understand what your code action :slight_smile: Sr
~~

i think you want search index called NAME
INDEX called TYPE
AND search word is : DEFINITION
It true ?

1 Like

Thank you for your answer ! I wanna know plz what do you mean by "the first time when you are indexing your document" ! can you show me plz an exemple of indexing document ?

I'm grateful for your answer ^ Tahnk you !

fields: ["NAME^5", "TYPE^1", "DEFINITION^3"]

By this line I attribute a weight to each field

And my index's name is gosport (as you can see in this line )

index: 'gosport'

Oh :slight_smile: Ok now i know your idea.
You want search : "queryTxt" , add synonym , use stopword in "queryTxt" ?

In my opinion, you can create one analyzer and stopword after create index "gosport". Before you index anydata to "gosport"

analyzer can auto add some synonym when you search
use synonym
https://www.elastic.co/guide/en/elasticsearch/guide/current/using-synonyms.html

create stop word
https://www.elastic.co/guide/en/elasticsearch/guide/current/using-stopwords.html

1 Like

Yes exactly that's what I'm trying to do but it dosen't work ! I think I have some problems with syntaxe !!!! I'm gonna try again