2

I am trying to search in documents with the following mapping:

 {
"products":{
  "properties":{
     "product_id":{
        "type":"string"
     },
     "naam":{
        "type":"string"
     },
     "merk":{
        "type":"string"
     },
     "lijn":{
        "type":"string"
     },
     "sku":{
        "type":"string"
     },
     "omschrijving":{
        "type":"string",
        "boost":"0.5"
     },
     "groep":{
        "type":"string"
     },
     "ean":{
        "type":"string",
        "boost":"2.0"
     },
     "kenmerken":{
        "type":"nested",
        "dynamic":true
     },
     "levertijd_min":{
        "type":"string"
     },
     "levertijd_max":{
        "type":"string"
     }
  }
}
}

I want to search in the "naam", "omschrijving" etc but also in the dynamic mappings of the nested document "kenmerken" I've created a couple of search querys but none of them seem to work.

Should I use a bool or a filter? or combinations of both?

Am I even close?

$params['body'] = array(
        'query' => array(
            'filtered' => array(
                'query' => array(
                    'match_all' => array()
                ),
                'filter' => array(
                    'or' => array(
                        array('term' => array(
                            'naam' => $_GET['ZOEKTERMEN'],
                        )),
                        array('terms' => array(
                            'omschrijving' => explode(" ", $_GET['ZOEKTERMEN'])
                        )),
                        array('terms' => array(
                            'merk' => explode(" ", $_GET['ZOEKTERMEN'])
                        )),
                        array('term' => array(
                            'product_id' => $_GET['ZOEKTERMEN']
                        )),
                        array('nested' => array(
                            'path' => 'kenmerken',
                            'query' => array(
                                'filtered' => array(
                                    'query' => array(
                                        'match_all' => array()
                                    ),
                                    'filter' => array(
                                        'term' => array(
                                            '_all' =>  $_GET['ZOEKTERMEN']
                                        )
                                    )
                                )
                            )
                        ))
                    )
                )
            )
        )
    );
Hawiak
  • 553
  • 1
  • 9
  • 32
  • Looking here it seems like strings in nested docs are copied to the *root* document's `_all` field. So your nested clause isn't doing what you need. https://www.elastic.co/guide/en/elasticsearch/reference/1.4/mapping-nested-type.html – Peter Dixon-Moses Nov 12 '15 at 18:05

2 Answers2

0

I am not into PHP but I think the problem is you are using term query to search and you have not specified "index": "not_analyzed" in your mapping.

Please Refer to the docs for more detail

You can either change your query from term to match or match_phrase. or make changes to mapping with "index": "not_analyzed" and reindex the data.

I hope this helps.

ChintanShah25
  • 12,366
  • 3
  • 43
  • 44
  • Should I continue to use filter? Just changing term/terms to match or match_phrase throws errors. Parse Failure [Failed to parse source – Hawiak Nov 05 '15 at 15:28
0

Since I needed an solution I decided to create a seperate string field in which I exploded the "kenmerken" field in. This works fine for now.

Hawiak
  • 553
  • 1
  • 9
  • 32