1

Below is the search definition of my document. I have field "expire" which is a timestamp in my document.Now I want to search documents using yql query if isActive="1" and test.expire - now() > 0.Can I achieve this by query?

search test {
    document test {
                field Id type string {
                    indexing: index|summary
                }

                field isActive type string {
                    indexing: index|summary
                }

                field expire type long {
                   indexing: index | summary
                }

                field detail type string {
                   indexing: summary
                }
}

}

If yes then what would be my query? How can I apply condition in my query?Please help

Mohammad Sunny
  • 371
  • 1
  • 3
  • 15

1 Answers1

1

YQL for this is

?query=select * from test where (isActive contains "1" and expire > nowTimestamp);&type=yql

You cannot use now() so you need to insert the timestamp yourself.

You could also construct the query in a Searcher component (bypassing the need to construct a YQL string).

Jon
  • 2,043
  • 11
  • 9
  • I will pass a yql query using REST api then again Do I have to construct query inside the searcher component?If I construct it then how will it bypass the construction of yql string? – Mohammad Sunny Dec 03 '18 at 05:39
  • You can programatically work on the parsed query tree in a custom searcher. https://docs.vespa.ai/documentation/searcher-development.html & this example https://github.com/vespa-engine/sample-apps/blob/master/basic-search-java/src/main/java/com/mydomain/example/ExampleSearcher.java#L23 where a single required AND term is added to the original query which was past through the http search api. – Jo Kristian Bergum Dec 03 '18 at 09:31