Multi match query and nested object


(Blanchet) #1

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:

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

and use this query:

{
  "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!


(Adrien Grand) #2

What do you mean by "not correct"?


(Blanchet) #3

With "and" operator and cross_field, it's search with shakespeare and juliette in "title" and shakespeare and juliette in "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.


(Adrien Grand) #4

It seems to work for me on elasticsearch 2.4.0:

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?


(Blanchet) #5

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,


(Blanchet) #6

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


(Blanchet) #7

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,


(Thomas Decaux) #8

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

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


(system) #9