More Like This Query (MLT) with nested objects

Hey :slight_smile:

I created an index with nested objects, kind of like this:

user:
    properties:
        name:
            type: text
        institutions:
            type: nested
            properties:
                name:
                    type: text
                description:
                    type: text
                members:
                    type: nested
                    properties:
                        name:
                            type: text
                        description:
                            type: text
        orders:
            type: nested
            properties:
                [...]

How can i use the More Like This Query, to find similar users based on name, institutions, orders and so on. This doesn't work:

GET /users/user/_search
{
  "query": {
    "more_like_this" : {
        "like" : [
        {
          "_index" : "users",
          "_type" : "user",
          "_id" : "1"
        }],
        "max_query_terms": 25,
        "min_term_freq": 1,
        "min_doc_freq": 1,
        "minimum_should_match": 1
    }
  }
}

I've tested it (only institutions + members, without orders) with Nested Query also:

POST /users/user/_search
{
  "query": {
    "nested": {
      "path": "institutions",
      "query": {
        "bool": {
          "should": [
            {
              "more_like_this": {
                "like" : [{
                  "_index" : "users",
                  "_type" : "user",
                  "_id" : "1"
                }],
                "max_query_terms": 25,
                "min_term_freq": 1,
                "min_doc_freq": 1,
                "minimum_should_match": 1
              }
            }, {
              "nested": {
                "path": "institutions.members",
                "query": {
                  "bool": {
                    "should": {
                      "more_like_this": {
                        "like" : [{
                          "_index" : "users",
                          "_type" : "user",
                          "_id" : "1"
                        }],
                        "max_query_terms": 25,
                        "min_term_freq": 1,
                        "min_doc_freq": 1,
                        "minimum_should_match": 1
                      }
                    }
                  }
                }
              }
            }
          ]}
        }
      }
    }
  }
}

If there are the same terms in name + description in institutions from different users (A + B) it matchs. But if i use only the same terms in name + description in institution from user A and in one member of some institution of user B, it not matchs. It seems like the MLT Query compare the users only in the same stage (institution XOR member). Another disadvantage is that this kind of query becomes very complexe with more than 60 nested types.

What's the best practice to deal with this issue?

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