Greg Finzer
Greg Finzer

Reputation: 7074

How to do a Exact Match On One Field and Partial Match On Another in Elasticsearch?

There is a business requirement to have an exact match on the entity_type field and then a partial match on the predicates.name.value field with the results sorted for exact matches first.

Below is what I have for the query for the exact match for both. How would I change it so that it is a partial match for the predicates.name.value field with the exact matches sorted first?

self.search = {
    "query" : {
        "bool" : {
            "must" : [
                {
                    "match" : {
                        "entity_type" : entity_type
                    }
                },
                {
                    "match" : {
                        "predicates.name.value" : criteria
                    }
                },

            ]
        }
    }
}

Upvotes: 0

Views: 149

Answers (1)

Alfred
Alfred

Reputation: 21406

Can you try this;

self.search = {
    "query" : {
        "bool" : {
            "must" : [
                {
                    "match" : {
                        "entity_type" : entity_type
                    }
                },
                {"query": {"wildcard": {"predicates.name.value": {"value": "*criteria*"}}}},

            ]
        }
    }
}

Upvotes: 1

Related Questions