2

I have integrated elastic search in laravel with help of below tutorial.

https://appdividend.com/2018/06/30/laravel-elasticsearch-tutorial-example/

According to this tutorial search with single fields is working fine. i.e.

// Article table has column 'title','body' and 'tags'.

 Route::get('/search', function() {
      $articles = Article::searchByQuery(['match' => ['title' => 'Test']]);
      return $articles;
 });

But i want to search with multiple column values like 'title' ,'body' etc.

Anyone suggest an idea how to search with multiple column?

2 Answers 2

5

You can use the multimatch query, below is some sample how this can be done.

GET _search
{
    "query": {
        "bool": {
            "must": {
              "multi_match" : {
                "query": "stuff you want to seach", 
                "type":  "cross_fields",
                "fields": [ 
                   "title^10",
                   "body^9",
                   "tags^8"
                ]
              }
            }
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

-2
$array = modelName::searchByQuery(
    [
        'multi_match' => [
            'query' => 'search param', 
            'type' =>  "cross_fields",
            'fields' => [ 
                'field1',
                'field2',
                'more fields'
            ]
        ]
    ]
);

1 Comment

Please don't post only code as answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually more helpful and of better quality, and are more likely to attract upvotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.