# Error in syntax with multi fields search

**URL:** <https://discuss.elastic.co/t/error-in-syntax-with-multi-fields-search/157473>\
**Category:** Elasticsearch\
**Created:** [November 20, 2018, 6:07am UTC](https://discuss.elastic.co/t/error-in-syntax-with-multi-fields-search/157473 "2018-11-20T06:07:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ivancsvetkov](https://avatars.discourse-cdn.com/v4/letter/i/ee7513/32.png) [@ivancsvetkov](https://discuss.elastic.co/u/ivancsvetkov)\
**Post date:** [November 20, 2018, 6:07am UTC](https://discuss.elastic.co/t/error-in-syntax-with-multi-fields-search/157473/1 "2018-11-20T06:07:47Z")

</div>

Hello!  
I look at "Elasticsearch Do's, Don'ts and Pro-Tips - Itamar Syn Hershko" video tutorial at  
[https://www.youtube.com/watch?v=c9O5\_a50aOQ](https://www.youtube.com/watch?v=c9O5_a50aOQ) I see condition on several  
fiedls [https://imgur.com/a/17zAZ4w](https://imgur.com/a/17zAZ4w) and try to make it in my Laravel 5.7 app(with elasticsearch/elasticsearch plugin) as :

```auto
        $elasticQuery = [
            "bool" => [
                "must" => [
                    "multi_match" => [
                        "query" => $text,
                        "fields" => ["name^4", "description"]
                    ],
                ],
                "should" => [
                    "term" => [
                        "category_id" => 1,
                    ]
                ]
            ]
        ];

```

But I got error :

```auto
{"error":{"root_cause":[{"type":"parsing_exception","reason":"[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":133}],"type":"parsing_exception","reason":"[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]","line":1,"col":133},"status":400}

```

Can you say why error and which syntax is valid?

When I use simple condition:

```auto
                $elasticQuery = [
                    'multi_match' => [
                        'query' => $text,
                        'fields' => ['name^4', 'description'],
                    ],
                ];
I got valid results as I expected...

```

Thanks!

---

<div class="post-metadata">

**Author:** ![ivancsvetkov](https://avatars.discourse-cdn.com/v4/letter/i/ee7513/32.png) [@ivancsvetkov](https://discuss.elastic.co/u/ivancsvetkov)\
**Post date:** [November 21, 2018, 8:51am UTC](https://discuss.elastic.co/t/error-in-syntax-with-multi-fields-search/157473/2 "2018-11-21T08:51:07Z")

</div>

Making some search I found working next syntax :

```auto
        $elasticQuery = [
            "bool" => [
                'should' => [

                        [
                                "multi_match" => [
                                    "query" => $text,
                                    "type" => "cross_fields",
                                    "fields" => [
                                        "name^4",
                                        "description"
                                    ]
                                ]
                        ],

                        [
                            'match' => [
                                'category_id' => [
                                    'query' => 1,
                                ]
                            ]
                        ],

                        [
                            'match' => [
                                'category_id' => [
                                    'query' => 3,
                                ]
                            ]
                        ],
                    
                ]
            ]
        ];

```

when I need to make search by text fields and array of category (1 and 3) in example above.

It works, but looks like it works like "OR" condition, but I need to make restriction as "AND" if to use sql terminology...

Which way is correct to make restriction as "AND" ?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 19, 2018, 8:51am UTC](https://discuss.elastic.co/t/error-in-syntax-with-multi-fields-search/157473/3 "2018-12-19T08:51:09Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
