Home > database >  Searching a text in multiple columns with elasticsearch
Searching a text in multiple columns with elasticsearch

Time:02-22

I use MySQL as a database and elasticsearch as a search engine which are running on my localhost. So,there is too many database columns that I want to search in but i dont know how to create a query about it. For example I want to search 'example_text' in more than one column, how can I include other columns to this example query:

{
  "query": {
    "fuzzy": {
      "name": {
        "value": "example_text",
        "fuzziness": "2"
      }
    }
  }
}

In a nutshell, I want to search this 'example_text' in surname column and country column too. How can I do that?

Any helps would be appreciated. Thank you.

Have a healthy and happy day!

CodePudding user response:

Try this query:

{
  "query": {
    "multi_match": {
      "query": "example_text",
      "fields": [
        "column1",
        "column2"
      ],
      "fuzziness": "2"
    }
  }
}

See elastic docs

  • Related