# Query Across Indices and Apply Different Function Scores (get parsing exception unknown field error)

**URL:** <https://discuss.elastic.co/t/query-across-indices-and-apply-different-function-scores-get-parsing-exception-unknown-field-error/122982>\
**Category:** Elasticsearch\
**Created:** [March 7, 2018, 11:27pm UTC](https://discuss.elastic.co/t/query-across-indices-and-apply-different-function-scores-get-parsing-exception-unknown-field-error/122982 "2018-03-07T23:27:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cpritcha](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cpritcha/32/28545_2.png) [@cpritcha](https://discuss.elastic.co/u/cpritcha)\
**Post date:** [March 7, 2018, 11:27pm UTC](https://discuss.elastic.co/t/query-across-indices-and-apply-different-function-scores-get-parsing-exception-unknown-field-error/122982/1 "2018-03-07T23:27:58Z")

</div>

I would like to implement a search across indexes that applies different function scoring for each index so that more recent jobs and events rank higher in search results.

Suppose the website has jobs, events given by mappings below.

```auto
DELETE event
DELETE job
PUT event
{
  "mappings": {
    "core_job": {
      "properties": {
        "date_created": {
          "type": "date",
          "include_in_all": false
        },
        "start_date": {
          "type": "date",
          "include_in_all": false
        },
        "title": {
          "type": "text",
          "include_in_all": true
        }
      }
    }
  }
}

PUT job
{
  "mappings": {
    "core_job": {
      "properties": {
        "date_created": {
          "type": "date",
          "include_in_all": false
        },
        "title": {
          "type": "text",
          "include_in_all": true
        }
      }
    }
  }
}

PUT event/core_event/core_event:1
{
  "date_created": "2013-05-02T16:23:55+00:00",
  "start_date": "2013-07-02T16:23:55+00:00",
  "title": "Ecology Event"
}

PUT job/core_job/core_job:1
{
  "date_created": "2014-05-02T16:23:55+00:00",
  "title": "Ecology Job"
}

```

When I try this query

```auto
GET event,job/_search
GET event,job/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "function_score": {
            "query": {
              "bool": {
                "must": [
                  {
                    "type": {
                      "value": "core_job"
                    }
                  },
                  {
                    "match": {
                      "_all": "ecology"
                    }
                  }
                ]
              }              
            },
            "functions": [
              {
                "filter": {
                  "type": {
                    "value": "core_job"
                  }
                }, 
                "gauss": {
                  "date_created": {
                    "scale": "10d"
                  }
                }
              }
            ]
          }
        },
        {
          "function_score": {
            "query": {
              "bool": {
                "must": [
                  {
                    "type": {
                      "value": "core_job"
                    }
                  },
                  {
                    "match": {
                      "_all": "ecology"
                    }
                  }
                ]
              }              
            },
            "functions": [
              {
                 "filter": {
                   "type": {
                     "value": "core_job"
                   }
                }, 
                "gauss": {
                  "date_created": {
                    "scale": "10d"
                  }
                }
              },
              {
                "script_score": {
                  "script": "1"
                }
              }
            ],
            "score_mode": "sum"
          }
        },
        {
          "function_score": {
            "query": {
              "bool": {
                "must": [
                  {
                    "type": {
                      "value": "core_event"
                    }
                  }
                ]
              }
            },
            "functions": [
              {
                "filter": {
                  "type": {
                    "value": "core_event"
                  }
                }, 
                "gauss": {
                  "start_date": {
                    "scale": "10d"
                  }
                }
              },
              {
                "script_score": {
                  "script": "1"
                }
              }
            ],
            "score_mode": "sum"
          }
        }
      ]
    }
  }
}

```

I get a response of

```auto
{
  "took": 0,
  "timed_out": false,
  "_shards": {
    "total": 10,
    "successful": 5,
    "skipped": 0,
    "failed": 5,
    "failures": [
      {
        "shard": 0,
        "index": "job",
        "node": "Dinaz4RTSceo1xZ2_PX70Q",
        "reason": {
          "type": "parsing_exception",
          "reason": "unknown field [start_date]",
          "line": 1,
          "col": 0
        }
      }
    ]
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "event",
        "_type": "core_event",
        "_id": "core_event:1",
        "_score": 1,
        "_source": {
          "date_created": "2013-05-02T16:23:55+00:00",
          "start_date": "2013-07-02T16:23:55+00:00",
          "title": "Ecology Event"
        }
      }
    ]
  }
}

```

How should the query be changed to that ElasticSearch does not try to search for `start_date` on the `job` index (or is there a better approach to score differently for each index)?

I'm using ElasticSearch 5.6.6 (since I'm using [Wagtail](http://docs.wagtail.io/en/v1.13.1/topics/search/index.html))

---

<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:** [April 4, 2018, 11:28pm UTC](https://discuss.elastic.co/t/query-across-indices-and-apply-different-function-scores-get-parsing-exception-unknown-field-error/122982/2 "2018-04-04T23:28:22Z")

</div>

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