# Faceted search query with SEO urls

**URL:** <https://discuss.elastic.co/t/faceted-search-query-with-seo-urls/46036>\
**Category:** Elasticsearch\
**Created:** [April 1, 2016, 9:50am UTC](https://discuss.elastic.co/t/faceted-search-query-with-seo-urls/46036 "2016-04-01T09:50:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xinox](https://avatars.discourse-cdn.com/v4/letter/x/41988e/32.png) [@xinox](https://discuss.elastic.co/u/xinox)\
**Post date:** [April 1, 2016, 9:50am UTC](https://discuss.elastic.co/t/faceted-search-query-with-seo-urls/46036/1 "2016-04-01T09:50:28Z")

</div>

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:

- [http://myapp/jobs/london](http://myapp/jobs/london) -\> returning all the jobs containing london in locations.

- [http://myapp/jobs/accounting](http://myapp/jobs/accounting) -\> returning all the jobs containing accounting in sectors

- [http://myapp/jobs/london/accounting](http://myapp/jobs/london/accounting) -\> returning only jobs with location in london and sector in accounting (the intersection).

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!! 🙂

---

<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:** [July 5, 2017, 11:03pm UTC](https://discuss.elastic.co/t/faceted-search-query-with-seo-urls/46036/2 "2017-07-05T23:03:22Z")

</div>


