Faceted search query with SEO urls

Hi there,

I am working on a faceted search component to filter jobs using two categories: Sectors and Locations. The jobs index have a lot of fields, to simplify I only show the most important to perform the query:

{
  "jobs": {
    "mappings": {
      "job": {
        "dynamic": "strict",
        "properties": {
          "locations": {
            "type": "nested",
            "properties": {
              "name": {
                "type": "string",
                "fields": {
                  "raw": {
                    "type": "string",
                    "index": "not_analyzed"
                  }
                }
              }
            }
          }
        },
        "sectors": {
          "type": "string",
          "fields": {
            "raw": {
              "type": "string",
              "index": "not_analyzed"
            }
          }
        },
        "salary": {
          "type": string
        }
      }
    }
  }
}
}

Locations is a nested object with some other information. A sample data used in the applications is:

{
  "jobs": [
    {
      "sectors": [
        "Accounting"
      ],
      "salary": "35K",
      "locations": {
        "name": [
          "London",
          "Paris"
        ]
      }
    },
    {
      "sectors": [
        "Accounting"
      ],
      "salary": "40K",
      "locations": {
        "name": [
          "Berlin",
          "Rome"
        ]
      }
    },
    {
      "sectors": [
        "Sales",
        "Human Resources"
      ],
      "salary": "34k",
      "locations": {
        "name": [
          "Berlin"
        ]
      }
    }
  ]
}

I need to perform queries using SEO friendly urls, that is:

The problem is that I do not know if the first and second path variables are a sector or a location, so what I have is a string like "london accounting". I need to perform a query using this.

I have been trying different queries to get that. The most simple is to have a should group with three clauses:

{
  "query": {
    "bool": {
      "should": [
        {
          "query_string": {
            "query": "(london) OR (accounting)",
            "fields": [
              "sectors"
            ]
          }
        },
        {
          "nested": {
            "query": {
              "bool": {
                "must": {
                  "query_string": {
                    "query": "(london) OR (accounting)",
                    "fields": [
                      "locations.name"
                    ]
                  }
                }
              }
            },
            "path": "locations"
          }
        },
        {
          "bool": {
            "must": [
              {
                "query_string": {
                  "query": "(london) OR (accounting)",
                  "fields": [
                    "sectors"
                  ]
                }
              },
              {
                "nested": {
                  "query": {
                    "bool": {
                      "must": {
                        "query_string": {
                          "query": "(london) OR (accounting)",
                          "fields": [
                            "locations.name"
                          ]
                        }
                      }
                    }
                  },
                  "path": "locations"
                }
              }
            ]
          }
        }
      ],
      "minimum_should_match": "1"
    }
  }
}

I have also tried to play with minimum score, minimum_should_match percentages and other features with no result. I do not get to have a query to fit to this problem.

Any suggestion will be welcomed.

Thank you in advance!! :slight_smile: