# How to index a SQL Server table which contains foreign keys?

**URL:** <https://discuss.elastic.co/t/how-to-index-a-sql-server-table-which-contains-foreign-keys/220973>\
**Category:** Logstash\
**Created:** [February 26, 2020, 8:11am UTC](https://discuss.elastic.co/t/how-to-index-a-sql-server-table-which-contains-foreign-keys/220973 "2020-02-26T08:11:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![LaaKii](https://avatars.discourse-cdn.com/v4/letter/l/9de0a6/32.png) [@LaaKii](https://discuss.elastic.co/u/LaaKii)\
**Post date:** [February 26, 2020, 8:11am UTC](https://discuss.elastic.co/t/how-to-index-a-sql-server-table-which-contains-foreign-keys/220973/1 "2020-02-26T08:11:10Z")

</div>

I already indexed a simple SQL Table with an id and a couple of other values like name, etc.

But when it comes to indexing a table with foreign keys, im quite lost how to configure logstash.

My database is similar to this:

```
Table1{
id int,
userName varchar,
userNickname varchar,
idTable2 int,
idTable3 int
}

Table2{
id int,
address varchar
}

Table3{
id int,
macAdress varchar,
ipAdress varchar
}

```

So what's the best way to index a table which contains foreign keys? I can't be the first one trying this, or am I missing something?

I found a similar question, but there wasn't any answer it.

> [@Logstash: Index complex structure from jdbc input](https://discuss.elastic.co/t/logstash-index-complex-structure-from-jdbc-input/143447):
>
> Hi, I'd like to inject data from sql databases into Elasticsearch. Let say I have 3 tables: Company, Department and Employee. Each company has several department and each department has several employees. This example has 2 level of nested informations. I'd like to build and index a Company document like this: { "comp\_name": "World Company", "comp\_address": " 123 blablabla street...", "departments": [ { "dep\_id": 1, "dep\_name": "Human ressources", …

Thanks in advance!

---

<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:** [March 25, 2020, 8:11am UTC](https://discuss.elastic.co/t/how-to-index-a-sql-server-table-which-contains-foreign-keys/220973/2 "2020-03-25T08:11:12Z")

</div>

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