Multi_match bool query, error


(mattep) #1

Hi dear, any one can tell me where is the mistake in this sintax? i'm tryng to query different fields with different match type to get better result with no luck

{
	"_source": 
	{

	},
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
			"query": "||SEARCH_QUERY||",
			"fields": 
			[
				"0": "pname",
			],
			"type": "best_fields",
			"operator": "AND",
			"fuzziness": "auto"
		}
        },
        {
          "multi_match": {
			"query": "||SEARCH_QUERY||",
			"fields": 
			[
				"1": "shortdesc^2"		
			],
			"type": "most_fields",
			"operator": "OR",
			"minimum_should_match": "80%",
			"fuzziness": "auto"
		}
        },
		{
          "multi_match": {
			"query": "||SEARCH_QUERY||",
			"fields": [ 
			
			    "2": "feature",
				"3": "ref",
                "4": "mname",
                "5": "cname",
				"6": "shortdesc",		
				"7": "sref",				
				"8": "ean13"
			],
			"type": "cross_fields",
			"operator": "AND",
			"fuzziness": "auto"
		}
        }
		
      ]
    }
  },
"from": "0",
"size": "200"
}

(David Pilato) #2

Please format your code, logs or configuration files using </> icon as explained in this guide and not the citation button. It will make your post more readable.

Or use markdown style like:

```
CODE
```

This is the icon to use if you are not using markdown format:

There's a live preview panel for exactly this reasons.

Lots of people read these forums, and many of them will simply skip over a post that is difficult to read, because it's just too large an investment of their time to try and follow a wall of badly formatted text.
If your goal is to get an answer to your questions, it's in your interest to make it as easy to read and understand as possible.
Please update your post.


(mattep) #3

Thanks dear


(David Pilato) #4

What is the error you are getting?


(mattep) #5

I have no access to es log error on the software installed, but we get empty search result ! I only can check server side log if can help


(Magnus Kessler) #6

The "fields": [] arrays must only contain a list with the names of the fields on which the "query" is run. You're trying to use object syntax inside of the arrays. Also make sure there aren't any stray commas. See the multi_match query documentation for some examples.


(mattep) #7

Hi, thanks, the original app config use these syntax:

{
	"_source": 
	{

	},
	"query": 
	{
		"multi_match": 
		{
			"query": "||SEARCH_QUERY||",
			"fields": 
			{
				"0": "pname^50",
                                "1": "feature^5",
				"2": "ref^10",
                                "3": "mname^10",
                                "4": "cname^5",
				"5": "shortdesc^2",		
				"6": "sref^8",				
				"7": "ean13^1"
			},
			"type": "cross_fields",
			"operator": "AND",
			"minimum_should_match": "80%",
			"fuzziness": "auto"
		}
	},
	"from": "0",
	"size": "200"
},

And this work "great"


(Magnus Kessler) #8

The example you show there obviously uses object syntax instead of array syntax. I guess that in this case the code iterates over the values of the key value pairs.

If my understanding of multi_match is correct, then you can do away with the key names such as "0" and "1", and simply use a list of the values (["pname^50", "feature^5"]) instead.


(system) #9

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