Giter Club home page Giter Club logo

Comments (1)

davemoore- avatar davemoore- commented on June 1, 2024

@pczubak I'm sure my response comes too late for your needs, but I'll answer for the community. My takeaway from looking at this is that I should publish a tutorial with examples of the "weight" field, because the paragraph that exists in the specification might not explain the concept clearly enough.

In your case, my guess is that the desired behavior would have occurred if you raised the weight of the name_phone and address_phone resolvers instead of the name_city_state_postal resolver. That will allow you to match by name_city_state_postal, but only if the phone_number attribute either matches or does not exist.

Here's an example of the request and response after applying more weight to the resolvers with the phone_number attribute:

Request

POST _zentity/resolution/issue-44?_source=false
{
  "attributes": {
    "name": [ "Piotr's Restaurant" ],
    "state": [ "NY" ],
    "postal_code": [ "11217" ],
    "city": [ "New York" ],
    "phone_number": [ "2063108455" ]
  }
}

Response - Notice that the hits include docs that match the phone number and docs that lack any phone number, but there are no docs with a different phone number.

{
  "took" : 2,
  "hits" : {
    "total" : 2,
    "hits" : [ {
      "_index" : "issue-44",
      "_type" : "_doc",
      "_id" : "1",
      "_hop" : 0,
      "_query" : 0,
      "_attributes" : {
        "city" : [ "New York" ],
        "name" : [ "Piotr's Restaurant" ],
        "postal_code" : [ "11217" ],
        "state" : [ "NY" ]
      }
    }, {
      "_index" : "issue-44",
      "_type" : "_doc",
      "_id" : "2",
      "_hop" : 0,
      "_query" : 0,
      "_attributes" : {
        "city" : [ "New York" ],
        "name" : [ "Piotr's Restaurant" ],
        "phone_number" : [ "2063108455" ],
        "postal_code" : [ "11217" ],
        "state" : [ "NY" ]
      }
    } ]
  }
}

You can also view the queries that zentity sent to Elasticsearch to produce this result.

Request

POST _zentity/resolution/issue-44?hits=false&queries
{
  "attributes": {
    "name": [ "Piotr's Restaurant" ],
    "state": [ "NY" ],
    "postal_code": [ "11217" ],
    "city": [ "New York" ],
    "phone_number": [ "2063108455" ]
  }
}

Response - The logic of the queries shows that name, state, city, and postal_code must match, and that phone must either match or not exist.

{
  "took" : 2,
  "queries" : [ [ {
    "_hop" : 0,
    "_query" : 0,
    "_index" : "issue-44",
    "filters" : {
      "attributes" : {
        "tree" : {
          "0" : {
            "city" : {
              "name" : {
                "postal_code" : {
                  "state" : { }
                }
              }
            }
          },
          "1" : {
            "name" : {
              "phone_number" : { }
            }
          }
        },
        "resolvers" : {
          "name_city_state_postal" : {
            "attributes" : [ "city", "name", "postal_code", "state" ]
          },
          "name_phone" : {
            "attributes" : [ "name", "phone_number" ]
          }
        }
      },
      "terms" : null
    },
    "search" : {
      "request" : {
        "_source" : true,
        "query" : {
          "bool" : {
            "filter" : [ {
              "bool" : {
                "filter" : [ {
                  "term" : {
                    "city" : "New York"
                  }
                }, {
                  "bool" : {
                    "filter" : [ {
                      "term" : {
                        "name" : "Piotr's Restaurant"
                      }
                    }, {
                      "bool" : {
                        "filter" : [ {
                          "term" : {
                            "postal_code" : "11217"
                          }
                        }, {
                          "term" : {
                            "state" : "NY"
                          }
                        } ]
                      }
                    } ]
                  }
                } ]
              }
            }, {
              "bool" : {
                "should" : [ {
                  "bool" : {
                    "should" : [ {
                      "bool" : {
                        "must_not" : {
                          "exists" : {
                            "field" : "name"
                          }
                        }
                      }
                    }, {
                      "bool" : {
                        "must_not" : {
                          "exists" : {
                            "field" : "phone_number"
                          }
                        }
                      }
                    } ]
                  }
                }, {
                  "bool" : {
                    "filter" : [ {
                      "term" : {
                        "name" : "Piotr's Restaurant"
                      }
                    }, {
                      "term" : {
                        "phone_number" : "2063108455"
                      }
                    } ]
                  }
                } ]
              }
            } ]
          }
        },
        "size" : 1000
      },
      "response" : {
        "took" : 1,
        "timed_out" : false,
        "_shards" : {
          "total" : 1,
          "successful" : 1,
          "skipped" : 0,
          "failed" : 0
        },
        "hits" : {
          "total" : {
            "value" : 2,
            "relation" : "eq"
          },
          "max_score" : 0.0
        }
      }
    }
  } ] ]
}

Here is the test data I used to produce these examples:

Index

PUT issue-44
{"mappings":{"properties":{"name":{"type":"keyword"},"address_line_1":{"type":"keyword"},"address_line_2":{"type":"keyword"},"city":{"type":"keyword"},"state":{"type":"keyword"},"postal_code":{"type":"keyword"},"phone_number":{"type":"keyword"}}}}

Documents

POST issue-44/_bulk?refresh
{"index": { "_id": 1 }}
{"name":"Piotr's Restaurant","state":"NY","postal_code":"11217","city":"New York"}
{"index": { "_id": 2 }}
{"name":"Piotr's Restaurant","state":"NY","postal_code":"11217","city":"New York","phone_number":"2063108455"}
{"index": { "_id": 3 }}
{"name":"Piotr's Restaurant","state":"NY","postal_code":"11217","city":"New York","phone_number":"5550001234"}

Entity model

PUT _zentity/models/issue-44
{
  "attributes": {
    "name": {},
    "address_line_1": {},
    "address_line_2": {},
    "city": {},
    "state": {},
    "postal_code": {},
    "phone_number": {}
  },
  "resolvers": {
    "name_full_address": {
      "attributes": [
        "name", "address_line_1", "address_line_2", "city", "state", "postal_code"
      ],
      "weight": 100
    },
    "name_full_address_one_line": {
      "attributes": [
        "name", "address_line_1", "city", "state", "postal_code"
      ],
      "weight": 100
    },
    "loose_name_exact_address": {
      "attributes": [
        "loose_name", "address_line_1_exact", "city", "state", "postal_code"
      ],
      "weight": 100
    },
    "name_phone": {
      "attributes": [
        "name", "phone_number"
      ],
      "weight": 150
    },
    "name_address_postal": {
      "attributes": [
        "name", "address_line_1", "postal_code"
      ],
      "weight": 100
    },
    "name_address_city_state": {
      "attributes": [
        "name", "address_line_1", "city", "state"
      ],
      "weight": 100
    },
    "address_phone": {
      "attributes": [
        "phone_number", "address_line_1", "city", "state", "postal_code"
      ],
      "weight": 150
    },
    "name_city_state_postal": {
      "attributes": [
        "name", "city", "state", "postal_code"
      ],
      "weight": 100
    }
  },
  "matchers": {
    "exact": {
      "clause": {
        "term": {
          "{{ field }}": "{{ value }}"
        }
      }
    }
  },
  "indices": {
    "issue-44": {
      "fields": {
        "name": {
          "attribute": "name",
          "matcher": "exact"
        },
        "address_line_1": {
          "attribute": "address_line_1",
          "matcher": "exact"
        },
        "address_line_2": {
          "attribute": "address_line_2",
          "matcher": "exact"
        },
        "city": {
          "attribute": "city",
          "matcher": "exact"
        },
        "state": {
          "attribute": "state",
          "matcher": "exact"
        },
        "postal_code": {
          "attribute": "postal_code",
          "matcher": "exact"
        },
        "phone_number": {
          "attribute": "phone_number",
          "matcher": "exact"
        }
      }
    }
  }
}

from zentity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.