How to search through multiple fields with elasticsearch? How to search through multiple fields with elasticsearch? elasticsearch elasticsearch

How to search through multiple fields with elasticsearch?


The problem is the type: keyword in your mapping for fields description and title. Keyword type fields are not analyzed i.e they store the indexed data exactly like it was sent to elastic. It comes into use when you want to match things like unique IDs etc. Read: https://www.elastic.co/guide/en/elasticsearch/reference/current/keyword.html

You should read about analyzers for elasticsearch. You can create your custom analyzers very easily which can change the data you send them in different ways, like lowercasing everything before they index or search. Luckily, there are pre-configured analyzers for basic operations such as lowercasing. If you change the type of your description and title fields to type: text, your query would work.Read: https://www.elastic.co/guide/en/elasticsearch/reference/current/text.html

Also, i see you have dynamic templates configured for your index. So, if you do not specify the mappings for your index explicitly, all your string fields (like description and title) will be treated as type: keyword.If you build your index like this:

PUT index_name{  "mappings": {    index_type: {      "properties": {        "description": {"type": "text"},        "title": {"type": "text"}, ...      }    }  }}

your problem should be solved. This is because type: text fields are analyzed by the standard analyzer by default which lowercases the input, among other things. Read: https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-standard-analyzer.html