In Elasticsearch, given the following document structure:
"workhistory": {
"positions": [{
"company": "Some company",
"position": "Some Job Title",
"start": 1356998400,
"end": 34546576576,
"description": "",
"source": [
"some source",
"some other source"
]
},
{
"company": "Some other company",
"position": "Job Title",
"start": 1356998400,
"end": "",
"description": "",
"source": [
"some other source"
]
}]
}
and mappings for this structure:
workhistory: {
properties: {
positions: {
type: "nested",
include_in_parent: true,
properties: {
company: {
type: "multi_field",
fields: {
company: {type: "string"},
original: {type : "string", analyzer : "string_lowercase"}
}
},
position: {
type: "multi_field",
fields: {
position: {type: "string"},
original: {type : "string", analyzer : "string_lowercase"}
}
}
}
}
}
}
I want to be able to search on "company" and match the document if company = "some company" etc. Then I want to to get the tf idf _score. I also want to create a function_score query to boost the score of this match, based on the values of the "source" field array. Basically, if the source contains "some source", boost _score with x amount. I can change the structure of the "source" property if needed.
This is what I got so far:
{
"bool": {
"should": [
{
"filtered": {
"query": {
"bool": {
"should": [
{
"bool": {
"should": [
{
"match": {
"workhistory.positions.company.original": "some company"
}
}
]
}
}
],
"minimum_should_match": "100%"
}
},
"filter": {
"and": [
{
"bool": {
"should": [
{
"term": {
"workhistory.positions.company.original": "some company"
}
}
]
}
}
]
}
}
},
{
"function_score": {
"query": {
"bool": {
"should": [
{
"bool": {
"should": [
{
"match": {
"workhistory.positions.company.original": "some company"
}
}
]
}
}
],
"minimum_should_match": "100%"
}
},
"filter": {
"and": [
{
"bool": {
"should": [
{
"term": {
"workhistory.positions.company.original": "some company"
}
}
]
}
}
]
}
}
}
]
}
}
There are some filters in here as well, cause I only want to return documents with the filtered value. In this example the filters and the query are basically the same, but in a bigger version of this query I have a few other "optional" matches to boost optional values etc. The function_score is not doing much right now, since I cant really figure out how to work with it. The goal is to be able to adjust the number of the boost in my application code and pass it in to the search query.
I'm using Elasticsearch version 1.3.4.