0
votes

I have a index with some nested informations and right now struggle with how make to make a query.

The index below represents a car piece and this piece belongs to 2 cars.

  {
    "_index": "items_production_20180411115923024",
    "_type": "item",
    "_id": "1232",
    "_score": 21.715849,
    "_source": {
      "description": "CUBO RODA TRASEIRA VW:GOL, VOYAGE G5/G6 09> C/ABS",
      "observation": null,
      "brand_id": "1 ",
      "product_line_id": "13",
      "line_id": "1",
      "line": "Rolamentos",
      "segment_id": "21",
      "segment": "cubo de roda",
      "application_features": [
        "4 furos"
      ],
      "original_codes": [
        " 5u0 501 611 "
      ],
      "original_brands": [
        "volkswagen"
      ],
      "vehicles": [
        {
          "id": "285",
          "brand": "volkswagen",
          "name": "golf",
          "years": [
            "2009",
            "2010",
            "2011",
            "2012",
            "2013",
            "2014",
            "2015",
            "2016",
            "2017",
            "2018"
          ]
        },
        {
          "id": "345",
          "brand": "volkswagen",
          "name": "jetta",
          "years": [
            "2015",
            "2016",
            "2017",
            "2018"
          ]
        }
      ]
    }
  }

I have to make the query match to one single result when search for the model and year of a car. Ie:

GET items_production_20180411115923024/_search
   {
     "query":{
    "bool":{
      "must":{
        "multi_match":{
          "query":"golf 2010",
          "type":"cross_fields",
          "operator":"and",
          "fields":[
            "vehicles.name^8",
            "vehicles.years^8"
          ]
        }
      }
    }
  },
  "size":10,"from":0
}

I have to return all docs wich are pieces of a golf year 2010. But my response is none?

What I'm doing wrong? How can I make this query?

2

2 Answers

0
votes

I see you have a typo in the query. Replace vehicle_names^8 with vehicles.name^8.

0
votes

Is vehicles.years an analyzed field? If not, it will not match against the term "golf 2010".

You might be able to use copy_to in your mapping to get terms from the name and the year in one field. Then you can do a simple query against that.