ES combat scenario 1: use of exists field

Business scenario : The data stored in the document has the following three fields: dg, ws, ls. These three fields have only one value in the same document. When ES serializes the document, empty values ​​are not serialized by default. At present, I only want to query dg or ws data with values. How to query?

Thinking : In MySQL, this scenario is equivalent to one field is not null, and the other two fields are null. And we know that ES does not serialize fields by default, so if it is MySQL, it is equivalent to the following writing:

select * from data_doc where dg is not null;

Solution : In ES, you can use exist to determine the existence of a field, written as follows:

{
    "query": {
        "exists": {
            "field": "dg"
        }
    }
}

Last modified on April 12, 2020 15:48:02

Guess you like

Origin www.cnblogs.com/ixan/p/12685741.html