# Compound Must Matches Not Working for Me

**URL:** <https://discuss.elastic.co/t/compound-must-matches-not-working-for-me/146226>\
**Category:** Elasticsearch\
**Created:** [August 27, 2018, 6:39pm UTC](https://discuss.elastic.co/t/compound-must-matches-not-working-for-me/146226 "2018-08-27T18:39:09Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Douglas\_McQuilken](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/douglas_mcquilken/32/44897_2.png) [@Douglas\_McQuilken](https://discuss.elastic.co/u/Douglas_McQuilken)\
**Post date:** [August 27, 2018, 6:39pm UTC](https://discuss.elastic.co/t/compound-must-matches-not-working-for-me/146226/1 "2018-08-27T18:39:09Z")

</div>

Everything works fine until I insert a second match statement with a MUST, see below.  
NOTE: Either individual MUST statement works as expected but in combination...  
Parses correctly BUT always returns zero hits.  
Assistance (rather than more frustration) would be greatly appreciated 😉

##############################################################

{"size": 1000,  
"query" : {  
"bool" : {  
"minimum\_should\_match": 1,  
"must" : [{"match": { "source": { "query": "", "fuzziness": "0","operator": "and"}}},  
{"match": { "today": {"query": "\<2018-238\>"}}}],  
"should" : [  
{"match": { "description": { "query": "\<- brass - -\>", "fuzziness": "0","operator": "and"}}},  
{"match": { "url": { "query": "\<- brass - -\>", "fuzziness": "0","operator": "and"}}},  
{"match": {"description": { "query": "\<\*\>","fuzziness": "0","operator": "and"}}}  
]  
,"must\_not":[  
{"match":{"description": "ss"}}  
]  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [August 28, 2018, 12:06pm UTC](https://discuss.elastic.co/t/compound-must-matches-not-working-for-me/146226/2 "2018-08-28T12:06:39Z")

</div>

Are you sure there are documents that match both of the `must` clauses? You can think of multiple `must` clauses as an AND - a document must match ALL of the clauses to be returned as a hit.

Maybe you can share an example of a document that matches each individual must clause, but not the combined two?

---

<div class="post-metadata">

**Author:** ![Douglas\_McQuilken](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/douglas_mcquilken/32/44897_2.png) [@Douglas\_McQuilken](https://discuss.elastic.co/u/Douglas_McQuilken)\
**Post date:** [August 28, 2018, 4:40pm UTC](https://discuss.elastic.co/t/compound-must-matches-not-working-for-me/146226/3 "2018-08-28T16:40:06Z")

</div>

Thanks, upon reviewing my post I realized that I mangled the example ☹

Following is:  
(1) a document which matches all criteria (I located this independently)  
(2) After that is the actual query which parsed but provided 0 hits.  
(3) Lastly, is the same DSL query without the MUST which results in this document (among hundreds more)  
##########################################################  
{"\_index":"bupstest9","\_type":"listings","\_id":"https:~~outerbanks.craigslist.org~bpo~d~30-nibral-4-blade-class-1~6652278553.html","\_score":9.197452,"\_source":{"url": "[https://outerbanks.craigslist.org/bpo/d/30-nibral-4-blade-class-1/6652278553.html","description](https://outerbanks.craigslist.org/bpo/d/30-nibral-4-blade-class-1/6652278553.html%22,%22description)": "@@30" nibral 4-BLADE CLASS 1 tuned props factory-direcT PRICES@@ - ","site": "Craigslist\_outer\_banks","city": "outer\_banks","state": "NorthCarolina","country": "US","source": "Craigslist","bupsid": "9227198270","year": "2018","day": "239","today": "2018-239"}}  
#########################################################  
{"size": 1000,  
"query" : {  
"bool" : {  
"minimum\_should\_match": 1,  
"must" : [{"match": { "source": { "query": "", "fuzziness": "0","operator": "and"}}},  
{"match": { "today": {"query": "\<2018-239\>"}}}],  
"should" : [  
{"match": { "description": { "query": "\<- nibral - prop\>", "fuzziness": "0","operator": "and"}}},  
{"match": { "url": { "query": "\<- nibral - prop\>", "fuzziness": "0","operator": "and"}}},  
{"match": { "description": { "query": "\<- nibral - propeller \>", "fuzziness": "0","operator": "and"}}},  
{"match": { "url": { "query": "\<- nibral - propeller \>", "fuzziness": "0","operator": "and"}}},  
{"match": { "description": { "query": "\<- ni-bral - prop\>", "fuzziness": "0","operator": "and"}}},  
{"match": { "url": { "query": "\<- ni-bral - prop\>", "fuzziness": "0","operator": "and"}}},  
{"match": { "description": { "query": "\<- ni-bral - propeller \>", "fuzziness": "0","operator": "and"}}},  
{"match": { "url": { "query": "\<- ni-bral - propeller \>", "fuzziness": "0","operator": "and"}}},  
{"match": {"description": { "query": "\<_\>","fuzziness": "0","operator": "and"}}}  
]  
,"must\_not":[  
{"match":{"description": "ss"}}  
]  
}  
}  
}  
####################################################  
{"size": 1000,  
"query" : {  
"bool" : {  
"should" : [  
{"match": { "description": { "query": "\<- nibral - prop\>", "fuzziness": "0","operator": "and"}}},  
{"match": { "url": { "query": "\<- nibral - prop\>", "fuzziness": "0","operator": "and"}}},  
{"match": { "description": { "query": "\<- nibral - propeller \>", "fuzziness": "0","operator": "and"}}},  
{"match": { "url": { "query": "\<- nibral - propeller \>", "fuzziness": "0","operator": "and"}}},  
{"match": { "description": { "query": "\<- ni-bral - prop\>", "fuzziness": "0","operator": "and"}}},  
{"match": { "url": { "query": "\<- ni-bral - prop\>", "fuzziness": "0","operator": "and"}}},  
{"match": { "description": { "query": "\<- ni-bral - propeller \>", "fuzziness": "0","operator": "and"}}},  
{"match": { "url": { "query": "\<- ni-bral - propeller \>", "fuzziness": "0","operator": "and"}}},  
{"match": {"description": { "query": "\<_\>","fuzziness": "0","operator": "and"}}}  
]  
,"must\_not":[  
{"match":{"description": "ss"}}  
]  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [August 28, 2018, 5:06pm UTC](https://discuss.elastic.co/t/compound-must-matches-not-working-for-me/146226/4 "2018-08-28T17:06:30Z")

</div>

I'm not sure what the first `match` clause is supposed to do. Why search for an empty string with `fuzziness` set to `0` and the `operator` set to `and`? If I execute that query agains the document that you posted it does not match the document. This clause is the cause of the entire query not matching your document.

```auto
GET bupstest9/_search
{
  "query": {
    "match": {
      "source": {
        "query": "",
        "fuzziness": "0",
        "operator": "and"
      }
    }
  }
}

```

PS Please format the code that you post here, as described [here](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It makes it much easier to read. 🙂

---

<div class="post-metadata">

**Author:** ![Douglas\_McQuilken](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/douglas_mcquilken/32/44897_2.png) [@Douglas\_McQuilken](https://discuss.elastic.co/u/Douglas_McQuilken)\
**Post date:** [August 28, 2018, 5:37pm UTC](https://discuss.elastic.co/t/compound-must-matches-not-working-for-me/146226/5 "2018-08-28T17:37:42Z")

</div>

It appears that you are working from the first example I posted which has a typo ☹  
Please refer to my subsequent posting which has a target document meeting the criteria as well as complete DSL examples.

In short, what I am attempting to accomplish is to have a MUST containing multiple match/queries. Therse would be ANDed together to filter the document set. Then I intended to use a SHOULD to process within this subset.

The query worked properly with a single match/query within the MUST.  
Once I added a second match/query, it parsed but failed to find known documents.  
I couldn't find exact examples to work from - so I paralleled the SHOULD construct......

Thanks for your continuing interest

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [August 28, 2018, 5:47pm UTC](https://discuss.elastic.co/t/compound-must-matches-not-working-for-me/146226/6 "2018-08-28T17:47:27Z")

</div>

Your second example (for the query that has 0 hits) has the following `must` clause:

`"must" : [{"match": { "source": { "query": "", "fuzziness": "0","operator": "and"}}}, {"match": { "today": {"query": "&lt;2018-239&gt;"}}}]`

Note that one of the two queries inside of that must clause, is the match clause that searches for an empty string with fuzziness 0 and operator AND. This query is your problem query.

---

<div class="post-metadata">

**Author:** ![Douglas\_McQuilken](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/douglas_mcquilken/32/44897_2.png) [@Douglas\_McQuilken](https://discuss.elastic.co/u/Douglas_McQuilken)\
**Post date:** [August 28, 2018, 6:18pm UTC](https://discuss.elastic.co/t/compound-must-matches-not-working-for-me/146226/7 "2018-08-28T18:18:08Z")

</div>

AHA - As we used to say the northeast "light dawns on Marblehead"  
NOTE; this is a town on the coast of Massachusetts

In any case, I failed to follow the thread insert code instructions ☹  
Thus, my query word is being ignored within this thread.  
It has the same syntax as the second match/query word, i.e. "LTCraigslistGT"

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [August 28, 2018, 6:42pm UTC](https://discuss.elastic.co/t/compound-must-matches-not-working-for-me/146226/8 "2018-08-28T18:42:52Z")

</div>

Ha, believe it or not, but I visited Marblehead last summer. It is a lovely town.

So, you're saying the `must` clause looks like this?

```auto
      "must": [
        {
          "match": {
            "source": {
              "query": "<Craigslist>",
              "fuzziness": "0",
              "operator": "and"
            }
          }
        },
        {
          "match": {
            "today": {
              "query": "<2018-239>"
            }
          }
        }
      ]

```

Let me ask you: why the angle brackets in your queries? Those should not be there. Anyway, they should not influence the search results normally.

Would you mind sharing the settings and the mappings of the index? Just do a

```auto
GET bupstest9

```

and post the output. If it's too large, maybe you can create [a gist](https://gist.github.com/) and share a link to that.

---

<div class="post-metadata">

**Author:** ![Douglas\_McQuilken](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/douglas_mcquilken/32/44897_2.png) [@Douglas\_McQuilken](https://discuss.elastic.co/u/Douglas_McQuilken)\
**Post date:** [August 28, 2018, 8:37pm UTC](https://discuss.elastic.co/t/compound-must-matches-not-working-for-me/146226/9 "2018-08-28T20:37:15Z")

</div>

I believe the angle brackets are left over from ES 2.x

{"bupstest9":{"aliases":{},"mappings":{"listings":{"properties":{"bupsid":{"type":"text"},"city":{"type":"text"},"country":{"type":"text"},"day":{"type":"text"},"description":{"type":"text","analyzer":"snowball"},"site":{"type":"text"},"source":{"type":"text"},"state":{"type":"text"},"today":{"type":"text"},"url":{"type":"text","analyzer":"snowball"},"year":{"type":"text"}}}},"settings":{"index":{"creation\_date":"1531007073465","number\_of\_shards":"5","number\_of\_replicas":"1","uuid":"TBJYwFCMRb-iM9xkqdMp-g","version":{"created":"6030099"},"provided\_name":"bupstest9"}}}}

---

<div class="post-metadata">

**Author:** ![Douglas\_McQuilken](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/douglas_mcquilken/32/44897_2.png) [@Douglas\_McQuilken](https://discuss.elastic.co/u/Douglas_McQuilken)\
**Post date:** [August 30, 2018, 12:11pm UTC](https://discuss.elastic.co/t/compound-must-matches-not-working-for-me/146226/10 "2018-08-30T12:11:28Z")

</div>

Finally, I have it working.  
The problem was in my (mis)use of the "operator" construct within the queries, within the matches, within the must...  
Thanks for your assistance.

---

<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:** [September 27, 2018, 12:11pm UTC](https://discuss.elastic.co/t/compound-must-matches-not-working-for-me/146226/11 "2018-09-27T12:11:29Z")

</div>

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