0

I want to control the analyzer in my search query.

At the moment my code looks like this:

client.execute(search in indexName / documentType query {
  bool {
    must(
      termQuery("email", email),
      termQuery("name", name)
    )
  }
}

How can I control the analyzer here?

Tomer
  • 2,398
  • 1
  • 23
  • 31

1 Answers1

1

Note that a term query does not analyze the search terms, so what you're looking for is probably a match query instead and it would go like this:

client.execute(search in indexName / documentType query {
  bool {
    must(
      termQuery("email", email),
      matchQuery("name", name)              <--- change this to match query
         .analyzer(StandardAnalyzer)        <--- add this line
    )
  }
}

The test cases are a good source of information as well. In the SearchDslTest.scala file you'll find how to set all possible properties of a match query.

Val
  • 207,596
  • 13
  • 358
  • 360
  • Thanks! is there a way to use a costume analyzer I created as part of my mapping? somehow tell the query, look here, and use this analyzer? – Tomer Dec 02 '15 at 14:12
  • Yes, you can [define your own analyzer](https://github.com/sksamuel/elastic4s/blob/ca409b775fd0acbd65c143c60cb1ef4ed5ee079b/elastic4s-core/src/main/scala/com/sksamuel/elastic4s/analyzers/AnalyzerDsl.scala) and then use it like any pre-defined ones. – Val Dec 02 '15 at 14:22
  • Looks like there is an option to define a custom anlayzer, but don't have the option to specify an already defined analyzer which was already defined as part of my index settings. is that right? – Tomer Dec 02 '15 at 14:29
  • 1
    I think you can pass in there anything that has a `name` property, so you can create a "fake" analyzer having the same name as the one you have already defined in your index and it should work. Best is to try it out. – Val Dec 02 '15 at 14:37