# Multi match query and nested object

**URL:** <https://discuss.elastic.co/t/multi-match-query-and-nested-object/55416>\
**Category:** Elasticsearch\
**Created:** [July 13, 2016, 2:07pm UTC](https://discuss.elastic.co/t/multi-match-query-and-nested-object/55416 "2016-07-13T14:07:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayblanchet](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ayblanchet](https://discuss.elastic.co/u/ayblanchet)\
**Post date:** [July 13, 2016, 2:07pm UTC](https://discuss.elastic.co/t/multi-match-query-and-nested-object/55416/1 "2016-07-13T14:07:54Z")

</div>

Hi,

Do you know how use multi match query with nested object in cross\_fields type,  
by example i wouldlike to get one document with "shakespeare romeo" with this document:

```auto
{
   "title": "romero & juliette",
   "authors": [{ "name":"shakespeare"},{"name":"Montesquieu"}]
}

```

and use this query:

```auto
{
  "multi_match":{
     "operator":"and",
     "type":"cross_fields",
     "query":"shakespeare juliette",
     "fields":["title","author.name"]

  }
}

```

I try to use shoud with on query with nested and an other with no nested query, but with the cross\_fields and "and" operator the result is not correct.

Thanks!

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [July 13, 2016, 2:15pm UTC](https://discuss.elastic.co/t/multi-match-query-and-nested-object/55416/2 "2016-07-13T14:15:15Z")

</div>

What do you mean by "not correct"?

---

<div class="post-metadata">

**Author:** ![ayblanchet](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ayblanchet](https://discuss.elastic.co/u/ayblanchet)\
**Post date:** [July 13, 2016, 2:29pm UTC](https://discuss.elastic.co/t/multi-match-query-and-nested-object/55416/3 "2016-07-13T14:29:07Z")

</div>

With "and" operator and cross\_field, it's search with shakespeare and juliette in "title" and shakespeare and juliette in "[author.name](http://author.name)". The two words is not in the two subquery of should. And if I change operator "and" to "or", if i search skakespeare and brian , it return my document but shakespeare is correct and brian not.

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [July 13, 2016, 2:55pm UTC](https://discuss.elastic.co/t/multi-match-query-and-nested-object/55416/4 "2016-07-13T14:55:53Z")

</div>

It seems to work for me on elasticsearch 2.4.0:

```auto
DELETE t

PUT t/t/1
{
   "title": "romeo & juliette",
   "author": [{ "name":"shakespeare"},{"name":"Montesquieu"}]
}

GET t/_search
{
  "query": {
    "multi_match": {
      "operator": "and",
      "type": "cross_fields", 
      "query": "shakespeare juliette",
      "fields": [
        "title",
        "author.name"
      ]
    }
  }
}

```

Could it be due to the fact that your query has a typo and uses `author.name` instead of `authors.name`?

---

<div class="post-metadata">

**Author:** ![ayblanchet](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ayblanchet](https://discuss.elastic.co/u/ayblanchet)\
**Post date:** [July 13, 2016, 3:17pm UTC](https://discuss.elastic.co/t/multi-match-query-and-nested-object/55416/5 "2016-07-13T15:17:48Z")

</div>

I try on other index it's works, but with my index it's doesn't...  
My index was created with these settings:

```
{
    "settings" : {
        "index" : {
            "number_of_shards" : 5,
            "number_of_replicas" : 1,
			"analysis" : {
				"tokenizer" : {
					"ngram_tokenizer" : {
						"type": "nGram",
						"min_gram": 4,
						"max_gram": 6,
						"token_chars": ["letter", "digit"]
					}
                },
				"analyzer" : {
					"french" : {
						"filter" : [
							"french_elision",
							"lowercase",
							"french_stop",
							"french_stemmer"
						], 
						"tokenizer" : "ngram_tokenizer", 
						"type" : "custom"
					}
				}, 
				"filter" : {
					"french_elision" : {
						"type" : "elision",
						"articles_case" : true,
						"articles" : [
						  	"l", 
						  	"m", 
						  	"t", 
						  	"qu", 
						  	"n", 
						  	"s",
						  	"j", 
						  	"d", 
						  	"c", 
						  	"jusqu", 
						  	"quoiqu",
						  	"lorsqu", 
						  	"puisqu"
						]
					},
					"french_stop": {
					  "type" : "stop",
					  "stopwords" : "_french_" 
					}
					,
					"french_stemmer": {
					  "type" : "stemmer",
					  "language" : "light_french"
					}
				}
			}
        }
    }
}

```

Thanks for your help,

---

<div class="post-metadata">

**Author:** ![ayblanchet](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ayblanchet](https://discuss.elastic.co/u/ayblanchet)\
**Post date:** [July 13, 2016, 7:46pm UTC](https://discuss.elastic.co/t/multi-match-query-and-nested-object/55416/6 "2016-07-13T19:46:27Z")

</div>

It's would seem it's the analyzer:french on attibute which is the problem.

---

<div class="post-metadata">

**Author:** ![ayblanchet](https://avatars.discourse-cdn.com/v4/letter/a/df705f/32.png) [@ayblanchet](https://discuss.elastic.co/u/ayblanchet)\
**Post date:** [July 25, 2016, 3:45pm UTC](https://discuss.elastic.co/t/multi-match-query-and-nested-object/55416/7 "2016-07-25T15:45:08Z")

</div>

Hi jprountz,

It's not work if the type for author is specified by "nested" type.  
How adapt the query for works with nested and not nested fields in cross\_field mode?

Thanks for your help,

---

<div class="post-metadata">

**Author:** ![ebuildy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ebuildy/32/6070_2.png) [@ebuildy](https://discuss.elastic.co/u/ebuildy)\
**Post date:** [May 24, 2017, 11:08pm UTC](https://discuss.elastic.co/t/multi-match-query-and-nested-object/55416/8 "2017-05-24T23:08:00Z")

</div>

Hello, you cannot use cross field between différent documents (what nested does).

Si instead, you could do a bool query with 2 matchs

---

<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:** [July 5, 2017, 10:00pm UTC](https://discuss.elastic.co/t/multi-match-query-and-nested-object/55416/9 "2017-07-05T22:00:05Z")

</div>


