# Use query\_string for full-text search in parent-child tables in ElasticSearch

**URL:** https://discuss.elastic.co/t/use-query-string-for-full-text-search-in-parent-child-tables-in-elasticsearch/78861
**Category:** Elasticsearch
**Created:** [March 16, 2017, 12:56pm UTC](https://discuss.elastic.co/t/use-query-string-for-full-text-search-in-parent-child-tables-in-elasticsearch/78861 "2017-03-16T12:56:12Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![BFISoftware](https://avatars.discourse-cdn.com/v4/letter/b/b5e925/32.png) [@BFISoftware](https://discuss.elastic.co/u/BFISoftware)
#### Post date: [March 16, 2017, 12:56pm UTC](https://discuss.elastic.co/t/use-query-string-for-full-text-search-in-parent-child-tables-in-elasticsearch/78861/1 "2017-03-16T12:56:12Z")

</div>

Hello,  
we have found a strange behavior inside ElasticSearch querying.  
We have two types which are connected together as parent (applicant) and child (attachment).

Mapping for parent table:

```
 {
 	"Applicant": {
 		"properties": {
 			"Name": {
 				"type": "string"
 			},
 			"Focus": {
 				"type": "string"
 			},
 			"KnowHowClassification": {
 				"type": "string"
 			}
 		}
 	}
 }

```

Mapping for child table:

```
{
	"Attachments_Applicant": {
		"_parent": {
			"type": "Applicant"
		},
		"properties": {
			"File": {
				"type": "attachment"
			}
		}
	}
}

```

We need to query all fields across both tables to find certain keywords and return parent document.  
For this we are using following query:

```
{
  "from": 0,
  "size": 100,
  "query": {
    "bool": {
      "should": [
        {
          "has_child": {
            "type": "Attachments_Applicant",
            "query": {
              "bool": {
                "must": [
                  {
                    "query_string": {
                      "query": “{{search}}”
                    }
                  }
                ]
              }
            }
          }
        },
        {
          "query_string": {
            "query": “{{search}}”
          }
        }
      ]
    }
  }
}

```

If we search for “java css” (without quotes) we find documents that have either or both the terms.

If we search for “+java +css” (without quotes) we find only documents that have both those terms in one of the tables. If one of the terms is in the applicant table and another one in attachment table, then those documents are not returned.

Is there a way to query all fields parent-child tables with query\_string which has required terms (+)?

---

<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: [April 13, 2017, 12:56pm UTC](https://discuss.elastic.co/t/use-query-string-for-full-text-search-in-parent-child-tables-in-elasticsearch/78861/2 "2017-04-13T12:56:23Z")

</div>

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