How to retrieve documents that match all of the words?

Hi, I am using the below DSL query:

{   
   "_source": [
        "title",
        "bench",
        "court",
        "id_",
        "verdict"
    ],
    "size": 10,
    "query": {
    	
        "bool": {
            "must": {
                
                    "multi_match": {
                    	"query": "I R coelho" 
                    ,
                    "fields": [
                        "title",
                        "content"
                    ]
                }
            },
        "filter": {
        	
        "term": {
          "verdict": "alllowed"
       }
        
        },
            "should": {
                "multi_match": {
                    "query": "I R coelho",
                    "fields": [
                        "title.standard^16",
                        "content.standard^2"
                    ]
                }
            }
            
        }
          
    
    },
    "highlight": 
    {
        "fields": {
            "title": {},
            "content": {}
        }
    }
}

But when I search for terms with multiple words like I R Coelho it returns results that have I R in them but not coelho. How do I make it search that the top query is always the one that matches all the words in the query?

Here is my current mapping:

{
    "courts_test": {
        "mappings": {
            "properties": {
                "author": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "bench": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "citation": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "content": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "court": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "date": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "id_": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "title": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
                "verdict": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                }
            }
        }
    }
}

Have a look at operator. https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#operator-min

1 Like

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