Adjacency matrix with between 2 nested fields

Hi all,
A document looks like :

{
  "name": "myname",
  "type": "mytype",
  "values": {
    "priority": "mypriority",
    "state": "`mystate"
  }
}

My mapping :

{
  "myindex": {
    "mappings": {
      "_doc": {
        "properties": {
          "name": {
            "type": "text",
            "fields": {
              "raw": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "type": {
            "type": "text",
            "fields": {
              "raw": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "values": {
            "type": "nested",
            "properties": {
              "priority": {
                "type": "text",
                "fields": {
                  "raw": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              },
              "state": {
                "type": "text",
                "fields": {
                  "raw": {
                    "type": "keyword",
                    "ignore_above": 256
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

It's ok to do an adjacency matrix between type and name :

aggs: {
  "myaggregation": {
    "adjacency_matrix": {
      "filters": {
        "nameAgg": {
          "terms": {
            "name.raw": [
              "myname"
            ]
          }
        },
        "type_mytype": {
          "terms": {
            "type.raw": [
              "mytype"
            ]
          }
        }
      }
    }
  }
}

But impossible between values.priority.raw and values.state.raw, the bucket is empty...

Does someone have a solution?

Thank you!

This looks about right:

DELETE test
PUT test
{
  "settings": {
	"number_of_shards": 1,
	"number_of_replicas": 0

  },
  "mappings": {
	"doc": {
	  "properties": {
		"obj": {
		  "type": "nested",
		  "properties": {
			"values":{
			  "type":"keyword"
			}
		  }
		}
	  }
	}
  }
}
POST test/doc/1
{
  "obj":[
	{"values":[1,2]},
	{"values":[1,2]},
	{"values":[10,20]}
	]
}
GET test/_search
{
  "size": 0,
  "aggs": {
	"my_values": {
	  "nested": {
		"path": "obj"
	  },
	  "aggs": {
		"my_graph": {
		  "adjacency_matrix": {
			"filters": {
			  "1": {
				"term": {
				  "obj.values": 1
				}
			  },
			  "2": {
				"term": {
				  "obj.values": 2
				}
			  },
			  "10": {
				"term": {
				  "obj.values": 10
				}
			  },
			  "20": {
				"term": {
				  "obj.values": 20
				}
			  }
			}
		  }
		}
	  }
	}
  }
}
1 Like

Thank you for your answer.
I think I don't have enough detail my mapping. So I updated my post above

In fact, it works perfectly.
I had misplaced this piece of code.
Thank you Mark :slight_smile: Have a good day.

1 Like

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