Elasticsearch how to use multi_match with wildcard

后端 未结 5 859
再見小時候
再見小時候 2020-12-13 03:55

I have a User object with properties Name and Surname. I want to search these fields using one query, and I found multi_match in the documentation, but I don\'t

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 04:21

    Alternatively you could use a query_string query with wildcards.

    "query": {
        "query_string": {
            "query": "*mar*",
            "fields": ["user.name", "user.surname"]
        }
    }
    

    This will be slower than using an nGram filter at index-time (see my other answer), but if you are looking for a quick and dirty solution...

    Also I am not sure about your mapping, but if you are using user.name instead of name your mapping needs to look like this:

    "your_type_name_here": {
        "properties": {
            "user": {
                "type": "object",
                "properties": {
                    "name": {
                        "type": "string"
                    },
                    "surname": {
                        "type": "string"
                    }
                }
            }
        }
    }
    

提交回复
热议问题