Hi All,
I have document structure like below:
{
“SURVEY_TYPE”:“FEEDBACK”,
“MENTION_TIME”:“2008-06-07 05:30:00”,
“ID”:21206,
“ACTIVE_FLAG”:true,
“SOURCE_ID”:100115,
“CONTENTS”:[
{
"ACTIVE_FLAG":true,
"PREDEFINED":false,
"MD5":"911d10c91c6c80afb0a1a4d4ab786d24",
"QUESTION_ID":1000000000,
"STATUS":"P",
"PUBLISHING_API_STATUS":"N",
"OPTION_ID":1,
"MODIFIED_TIME":"2015-08-18 10:31:08",
"SENTIMENTS":[
{
"GROUP_ID":"npaaru@bfountain.com_1394536948561",
"CONTENT_ID":2175967,
"CATEGORY_ID":4015,
"ACTIVE_FLAG":true,
"SCORE":1,
}
],
"NLP_FLAG":true,
"CREATED_TIME":"2014-03-11 09:18:29"
}
],
“REVIEW_COUNT”:1,
“LOCATION_ID”:0,
“OWNER_POST_FLAG”:false,
“PERSON_ID”:11489,
“RECOMMEND_FLAG”:true,
“HARVESTER_ID”:74177,
}
so i’ve the requirement to get the average score in minimum time using indexing,so i go through the docs having covering index example and i wrote below index:
CREATE INDEX idx_score ON default
((DISTINCT ARRAY
(DISTINCT ARRAY s.SCORE AND s.CATEGORY_ID FOR s IN c.SENTIMENTS END)
FOR c IN CONTENTS END),PERSON_ID,SURVEY_TYPE,LOCATION_ID,SOURCE_ID,CONTENTS)
WHERE MENTION_TIME>=‘2001-01-01’;
then i use below SELECT query to fetch the value using index “idx_score”,
EXPLAIN SELECT AVG( s.SCORE)
FROM default t
UNNEST t.CONTENTS c
UNNEST c.SENTIMENTS s
WHERE t.PERSON_ID=11489 AND s.CATEGORY_ID IN [4015,4015,4026,4034]and t.MENTION_TIME >=‘2001-01-01’ and t.MENTION_TIME<‘2016-03-07’ ;
BUT EXPLAIN SHOW BELOW:
{
“plan”: {
“#operator”: “Sequence”,
“~children”: [
{
“#operator”: “PrimaryScan”,
“index”: “#primary”,
“keyspace”: “default”,
“namespace”: “default”,
“using”: “gsi”
},
WHICH USING PRIMARY INDEX KEY.
so i have below question here:
Q1: Is the problem i’m using ALIAS name ,like default t and using it.
how to make se select query to using this index.
Q2: how to use this if i have a alias name in select query
Q3: if i use any one of attributes mention in create index in my select query it ,should take this index in run time.
Any help will be appropriated.