opensearch index - concatenate fields - kibana

I have this index:
{
{
"first-level-id":"foo",
"second-level-id":"bar"
"score":100
},
{
"first-level-id":"foo",
"second-level-id":"bar"
"score":10
},
{
"first-level-id":"foo",
"second-level-id":"bar"
"score":100
}
}
Is it possible to index the concatenation of
first-level-id
second-level-id
in another field of the index?
This can help me with queries.

Related

Struggling with filtering Drupal data in Gatsby GraphQL query

I am using Drupal 8 JSON:API to expose data to my Gatsby site. I have built a GraphQL query to expose a list of "officers" which contains a field with a relationship to a set of "service periods". The data returned by the API is correct, but I would like to filter for only one specific child record (service period) and can not figure out how to do that. My query is:
officerList: allGroupContentLodgeGroupNodeOfficer(filter: {relationships: {entity_id: {relationships: {field_position: {elemMatch: {relationships: {field_service_period: {drupal_internal__tid: {eq: 203}}}}}}}}}) {
edges {
node {
r: relationships {
entity_id {
r: relationships {
field_position {
r: relationships {
field_position {
name
}
field_service_period {
name
drupal_internal__tid
}
}
}
}
title
}
}
}
}
}
}
The resulting JSON set is:
"data": {
"officerList": {
"edges": [
{
"node": {
"r": {
"entity_id": {
"r": {
"field_position": [
{
"r": {
"field_position": {
"name": "Governor"
},
"field_service_period": {
"name": "2018 - 2019",
"drupal_internal__tid": 203
}
}
},
{
"r": {
"field_position": {
"name": "Junior Past Governor"
},
"field_service_period": {
"name": "2019 - 2020",
"drupal_internal__tid": 204
}
}
}
]
},
"title": "Tom Jones"
}
}
}
}
]
}
}
}
I understand the resulting set is correct because the child is within the root. However, I can not see how to filter the full query to include only certain child records. Is this even possible? I have seen some implementations of GraphQL that seem to allow filters to be placed on children, but I don't think this is possible in Gatsby.
I have searched everywhere for possible solutions and have been banging my head against the wall for a few days. Any insight is GREATLY appreciated!
TIA!

How to run a `$set` and `$pull` within a Meteor method?

I want to update a collection called SMUProfiles, through a method called classroom.delete. I want to pull out the classroom_id from 2 places inside SMUProfiles i.e. one inside classrooms.owner which has an array of codes, and the other inside array classrooms.students.
I have successfully one the $set part, and now trying to add the $pull, but $pull doesn't seem to work.
Can we do the $set and $pull in such way?
/* Method for deleting Classroom */
'classroom.delete'(classroom_id) {
if (!this.userId) {
throw new Meteor.Error('not-authorised');
}
Classrooms.remove(classroom_id)
let classids = Classrooms.find({ owner: this.userId }).fetch().map(function(classrooms){
return classrooms._id })
//console.log(classids);
SMUProfiles.update({
owner: this.userId,
}, {
$set: {
'classrooms.owner': classids
},
$pull: {
'classrooms.students': classroom_id
}
}
)
}
You're trying to $set and $pull on the same field in the same update - the two operations conflict; so no, you can't use these operators in this way.
You could easily split this into two:
SMUProfiles.update(
{ owner: this.userId },
{ $set: { 'classrooms.owner': classids },
);
SMUProfiles.update(
{ owner: this.userId },
{ $pull: { 'classrooms.students': classroom_id },
);
See e.g. this answer

Getting custom fields in gatsby-plugin-feed

I can't figure out how to use the gatsby-plugin-feed to add some custom content from my frontmatter to the rss feed. Here is my config:
{
resolve: `gatsby-plugin-feed`,
options: {
query: `
{
site {
siteMetadata {
title
description
siteUrl
site_url: siteUrl
}
}
}
`,
feeds: [
{
serialize: ({ query: { site, allMarkdownRemark } }) => {
return allMarkdownRemark.edges.map(edge => ({
...edge.node.frontmatter,
description: edge.node.excerpt,
url: site.siteMetadata.siteUrl + edge.node.fields.slug,
guid: site.siteMetadata.siteUrl + edge.node.fields.slug,
}));
},
query: `
{
allMarkdownRemark(
limit: 1000,
sort: { order: DESC, fields: [fields___prefix] },
filter: { fields: { source: {eq: "posts"}, slug: { ne: null } } }
) {
edges {
node {
excerpt
html
fields {
slug
prefix
}
frontmatter {
title
subtitle
tags
categories
youtube
}
}
}
}
}
`,
output: '/rss.xml',
},
],
},
},
I thought that using the spread operator on the edge.node.frontmatter object would add all of the fields but that resulting item is missing a ton of the frontmatter fields.
I am sure I am missing something, or I don't understand something about rss feeds. Can anyone point me in the correct direction? Thank you.

Elasticsearch - Count distinct

I have a basic index with logs
Some logs are visit of user1 to user2
I managed to count the total of visits a user has received, but I don't know how count the total of distinct users a user has received
This is giving me all the logs for a user
{
"post_filter":{
"bool":{
"must":[
{
"term":{
"message":"visit"
}
},
{
"term":{
"ctxt_user2":"733264"
}
}
]
}
},
"query":{
"match_all":{}
}
}
Actually, I'm using FoSElasticaBundle for Symfony2
$filter->addMust((new Term())->setTerm('message', 'visit'));
$filter->addMust((new Term())->setTerm('ctxt_user2', $this->search->getVisit()));
I read some pages in the ES doc with aggregator, but I never managed to get what I want
Convert to SQL, I just need
SELECT COUNT(DISCTING ctxt_user1)
FROM logs
WHERE ctxt_user2 = 733264
EDIT:
Cardinality seams to be what I need.
Now just need to find how use it with FosElasticaBundle
"aggs": {
"yourdistinctcount": {
"cardinality": {
"field": "ctxt_user1"
}
}
}
Try this query ( not tested...):
{
"query" : {
"bool":{
"must":[
{
"term":{
"message":"visit"
}
},
{
"term":{
"ctxt_user2":"733264"
}
}
]
}
},
"aggs": {
"yourdistinctcount": {
"terms": {
"field": "ctxt_user1"
}
}
}
}
The post_filter query cannot be used in your case. As it write on Elastic.co website: The post_filter is applied to the search hits at the very end of a search request, after aggregations have already been calculated.`
HtH,

Foselastica get only best matching child

NOTE: elasticsearch 1.7 and foselastica 3.1 is used!
How do I get only the best matching child in parent/child or nested?
I need to query the whole index (parent and chied fields). The query returns parents, and their children. But I only need parent and best matching child for the query.
I've tried to achieve it with TopChildren, HasChild and so on, but its not working.
This is what my query looks like
{
"query":{
"has_child":{
"type":"variants",
"query":{
"filtered":{
"query":{
"bool":{
"must":[
{
"match":{
"allField":{
"query":"shirt rot",
"operator":"AND",
"minimum_should_match":"80%",
"fuzziness":"0.8",
"analyzer":"custom_search_analyzer"
}
}
}
],
"should":[
{
"match":{
"shortName":{
"query":"shirt rot",
"operator":"AND",
"analyzer":"custom_search_analyzer",
"boost":5
}
}
}
]
}
},
"filter":{
"bool":{
"should":[
{
"terms":{
"customized":[
0
]
}
}
]
}
}
}
},
"max_children":1
}
}
}

Resources