# Adjacency matrix with between 2 nested fields

**URL:** <https://discuss.elastic.co/t/adjacency-matrix-with-between-2-nested-fields/143844>\
**Category:** Elasticsearch\
**Created:** [August 10, 2018, 9:30am UTC](https://discuss.elastic.co/t/adjacency-matrix-with-between-2-nested-fields/143844 "2018-08-10T09:30:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathieu\_Soyer](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@Mathieu\_Soyer](https://discuss.elastic.co/u/Mathieu_Soyer)\
**Post date:** [August 10, 2018, 9:30am UTC](https://discuss.elastic.co/t/adjacency-matrix-with-between-2-nested-fields/143844/1 "2018-08-10T09:30:00Z")

</div>

Hi all,  
A document looks like :

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

```

My mapping :

```auto
{
  "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` :

```auto
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!

---

<div class="post-metadata">

**Author:** ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)\
**Post date:** [August 10, 2018, 10:22am UTC](https://discuss.elastic.co/t/adjacency-matrix-with-between-2-nested-fields/143844/2 "2018-08-10T10:22:12Z")

</div>

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
				}
			  }
			}
		  }
		}
	  }
	}
  }
}
```

---

<div class="post-metadata">

**Author:** ![Mathieu\_Soyer](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@Mathieu\_Soyer](https://discuss.elastic.co/u/Mathieu_Soyer)\
**Post date:** [August 10, 2018, 11:29am UTC](https://discuss.elastic.co/t/adjacency-matrix-with-between-2-nested-fields/143844/3 "2018-08-10T11:29:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mathieu\_Soyer](https://avatars.discourse-cdn.com/v4/letter/m/90ced4/32.png) [@Mathieu\_Soyer](https://discuss.elastic.co/u/Mathieu_Soyer)\
**Post date:** [August 10, 2018, 12:01pm UTC](https://discuss.elastic.co/t/adjacency-matrix-with-between-2-nested-fields/143844/4 "2018-08-10T12:01:14Z")

</div>

> [@Mark\_Harwood](#):
>
> "my\_values": { "nested": { "path": "obj" }

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 7, 2018, 12:01pm UTC](https://discuss.elastic.co/t/adjacency-matrix-with-between-2-nested-fields/143844/5 "2018-09-07T12:01:17Z")

</div>

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