Query N1QL FTS facets

Hi!

I created a FTS with city field as keyword:

But when I try to get info abouts facets, it doesn´t get facet info.

Docs schema:

[
  {
    "_class": "XXXX.SchoolDocument",
    "address": "C/VIRGEN DEL MAR",
    "address_number": 2,
    "city": "ALMERIA",
    "collective": "HIJAS CARIDAD ANDALUCIA",
    "email": "XXX@HOTMAIL.COM",
    "index": "XXX_es",
    "latitude": 36.83756,
    "longitude": -2.46483,
    "name": "NTRA. SRA. DEL MILAGRO",
    "province": "ALMERIA",
    "school_id": 439007,
    "telephone": 95000000,
    "zip_code": 4002
  },
  (...)

This is my query (N1QL):

select s.*
from `XXX-local` s
WHERE  SEARCH(s,
   {"query": {
       "must": {
                   "conjuncts": [
                        {"field":"_class", "match": "XXXX.SchoolDocument"},
                        {"field":"province", "wildcard": "*ALM*"}
                    ]
       }
    },
  	"facets": {
		"cities": {
			"size": 5000,
			"field": "city"
		}
	},
    "fields": ["*"],
    "sort": ["-_id"],
    "size": 100, "from": 0
  }
)
;

Result by query, same as document saved (no facets section):

[
  {
    "_class": "XXXX.SchoolDocument",
    "address": "C/VIRGEN DEL MAR",
    "address_number": 2,
    "city": "ALMERIA",
    "collective": "HIJAS CARIDAD ANDALUCIA",
    "email": "XXX@HOTMAIL.COM",
    "index": "XXX_es",
    "latitude": 36.83756,
    "longitude": -2.46483,
    "name": "NTRA. SRA. DEL MILAGRO",
    "province": "ALMERIA",
    "school_id": 439007,
    "telephone": 950000000,
    "zip_code": 4002
  },
  (...)

What am I doing wrong?

Thanks in advance.

@mbracero
Not receiving facets in the result of a N1QL query(or FLEX query here) is expected. To receive facet information, you should use FTS queries directly.
Please let me know if you have any further doubts here, thanks!

Hi @aditi.ahuja thanks for the reply…

But I don´t really understand… When I execute that query, it´s resolved by FTS index:

How can I execute the query instead?

@mbracero The query is resolved by the FTS index - because everything you’re requesting is supported by the search index.

The response to your search request is going to contain 2 main subsections:

  • Hits (document IDs along side any stored field data that you’re requesting for)
  • Aggregate results (facets’ results)

Embedding search requests within N1QL queries is one way we allow for users to access their search indexes. You can also send your search request JSON directly to the search service this way …

curl -XPOST -H "content-type:application/json" -u <username>:<password> http://<ip>:8094/api/index/<indexName>/query -d
'  {"query": {
       "must": {
                   "conjuncts": [
                        {"field":"_class", "match": "XXXX.SchoolDocument"},
                        {"field":"province", "wildcard": "*ALM*"}
                    ]
       }
    },
  	"facets": {
		"cities": {
			"size": 5000,
			"field": "city"
		}
	},
    "fields": ["*"],
    "sort": ["-_id"],
    "size": 100, "from": 0
  }'

The hits section of the search response is the only content N1QL queries process at the moment - reason why you will not see any facet results as part of the N1QL query response.

If you intend to see facets results, our recommendation is for you to issue your search request (the JSON payload within the N1QL SEARCH function) directly to the search service.

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