adamfairholm / Elasticquent

Map Larvel Eloquent models to Elasticsearch types
MIT License
201 stars 38 forks source link

Querying by multiple form fields filter #34

Open florentsorel opened 9 years ago

florentsorel commented 9 years ago

Hi,

I'm new with Elastic. I would like to search by multiple form fields.

For example I have my form with: company_name, contacts.first_last_name.

In my Elastic structure I have company_name, contacts.firstname, contacts.lastname

I want search by name (concat firstname and lastname) but if I filled the company_name form field I want to search company_name AND firstname + lastname

I think it's working with concat field, but who to add other field ?

$clients = Client::searchByQuery([
    'multi_match' => [
        'query' => $request->get('first_last_name'),
        "type" => "cross_fields",
        'operator' => 'and',
        'fields' => [
            'contacts.firstname',
            'contacts.lastname',
        ]

    ]
]);

Btw, how to add some checkboxes to the query with Elasticquent ? Of course, firstname, lastname and company_name will be included in the query too. I think it's a complex filter :/

Thx.