Using eZ Publish 2014.11, I'd like to filter search results on an objectrelationlist field.
I use this code (I removed all parts that are not related to the objectrelatiolist field) :
$query->query = new Criterion\LogicalAnd(
array(
// ...
new Criterion\Field( 'myField', Criterion\Operator::EQ, my_value ),
// ...
)
);
According to the profiler, the resulting query looks like this (I removed all parts that are not related to the objectrelatiolist field) :
SELECT
-- ...
AND `ezcontentobject`.`id` IN (
SELECT
`contentobject_id`
FROM
`ezcontentobject_attribute`
WHERE
(
-- ...
AND (
`contentclassattribute_id` IN ('342')
AND `sort_key_string` = my_value
)
)
)
-- ...
Apparenty in the database sort_key_string is empty for the field row (in spite the existing relation shown in data_text field):
*************************** 385. row ***************************
attribute_original_id: 0
contentclassattribute_id: 342
contentobject_id: 137
data_float: 0
data_int: NULL
data_text: <?xml version="1.0" encoding="utf-8"?>
<related-objects><relation-list><relation-item priority="1" contentobject-id="67" contentobject-version="1" node-id="69" parent-node-id="2" contentclass-id="43" contentclass-identifier="theme" contentobject-remote-id="00162a519495cd3b956192ea30b68761"/><relation-item priority="2" contentobject-id="68" contentobject-version="1" node-id="70" parent-node-id="2" contentclass-id="43" contentclass-identifier="theme" contentobject-remote-id="853215e40ca057a787a8cea9cdd5ddce"/></relation-list></related-objects>
data_type_string: ezobjectrelationlist
id: 614
language_code: fre-FR
language_id: 2
sort_key_int: 0
sort_key_string:
version: 1
So my question is : is there any way to search content using a criterion on an objectrelationlist ?
I should have use the fieldRelation criterion like this :
new Criterion\FieldRelation( 'myField', Criterion\Operator::IN, array(my_value) ),
Related
Folks, I am trying to create a calculated column/measures and experiencing issues.
My Data-set looks like this:
City
Building Name
Test Date
Component
Test Result
Calculated Result
-
-
-
-
-
-
City1
Build1
1/3/2014
Component A
Pass
None
City1
Build1
1/11/2014
Component 1
Fail
Fail1
City1
Build1
1/11/2014
Component 2
Pass
Fail1
City1
Build1
1/11/2014
Component 3
Pass
Fail1
City1
Build1
1/06/2014
Component A
Fail
MultiFail
City1
Build1
1/06/2014
Component 1
Fail
MultiFail
City1
Build1
1/06/2014
Component 2
Pass
MultiFail
City1
Build1
1/06/2014
Component 3
Fail
MultiFail
I am looking at Component & Test Result columns, count list of Fails - grouped by Building Name and Date; then generate Calculated result depending on the number of components failed.
If Single component Test Result = fail - then Calculated Result = Fail1
If CountA(components Test Result = fail) <=2 then Calculated Result = Fail2
If CountA(components Test Result = fail) > 2 then Calculated Result = MultiFail
If Component1 AND ComponentA Test Result = Fail then Calculated Result = FailMail
So far, I tried various ways in solving this with a step ahead and 2 steps behind:
I created a calculated column to count # Fails to be used for Calculated Result and struggling to generate Calculated Result.
Tests_Failed =
CALCULATE(COUNT(Table[TestResult]),FILTER(Table,Table[date]=MAX(Table[date])
&& Table[TestResult]="Fail"))
Another way I tried approaching the problem
Calculated Result =
VAR Component = Table[Component]
VAR Date1 = Table[Test date]
VAR Build = Table[Building Name]
RETURN
CALCULATE(DISTINCTCOUNT('Table'[Component]), ALL(Table), FILTER('Table',
'Table'[Test Result]="Fail" && 'Table'[date] = Date1 &&
'Table'[Building Name]=Build)))
Can you try this
Measure =
VAR _1 =
CALCULATE (
CALCULATE (
DISTINCTCOUNT ( 'Table'[Component] ),
FILTER ( 'Table', 'Table'[Test Result] = "Fail" )
),
ALLEXCEPT ( 'Table', 'Table'[Building Name], 'Table'[Test Date] )
)
VAR _2 =
SWITCH (
TRUE (),
ISBLANK ( _1 ) = TRUE (), "None",
_1 = 1, "Fail1",
"MultiFail"
)
RETURN
_2
This program compiles correctly, we are on V7R3 - but when running it receives an SQLCOD of -101 and an SQLSTATE code is 54011 which states: Too many columns were specified for a table, view, or table function. This is a very small JSON that is being created so I do not think that is the issue.
The RPGLE code:
dcl-s OutFile sqltype(dbclob_file);
xfil_tofile = '/ServiceID-REFCODJ.json';
Clear OutFile;
OutFile_Name = %TrimR(XFil_ToFile);
OutFile_NL = %Len(%TrimR(OutFile_Name));
OutFile_FO = IFSFileCreate;
OutFile_FO = IFSFileOverWrite;
exec sql
With elm (erpRef) as (select json_object
('ServiceID' VALUE trim(s.ServiceID),
'ERPReferenceID' VALUE trim(i.RefCod) )
FROM PADIMH I
INNER JOIN PADGUIDS G ON G.REFCOD = I.REFCOD
INNER JOIN PADSERV S ON S.GUID = G.GUID
WHERE G.XMLTYPE = 'Service')
, arr (arrDta) as (values json_array (
select erpRef from elm format json))
, erpReferences (refs) as ( select json_object ('erpReferences' :
arrDta Format json) from arr)
, headerData (hdrData) as (select json_object(
'InstanceName' : trim(Cntry) )
from padxmlhdr
where cntry = 'US')
VALUES (
select json_object('header' : hdrData format json,
'erpReferenceData' value refs format json)
from headerData, erpReferences )
INTO :OutFile;
Any help with this would be very much appreciated, this is our first attempt at creating JSON for sending and have not experienced this issue before.
Thanks,
John
I am sorry for the delay in getting back to this issue. It has been corrected, the issue was with the "values" statement.
This is the correct code needed to make it work correctly:
Select json_object('header' : hdrData format json,
'erpReferenceData' value refs format json)
INTO :OutFile
From headerData, erpReferences )
My Elasticsearch index has more than 1000 fields due to my Sql schema and I get below exception:
{'type': 'illegal_argument_exception', 'reason': 'Limit of total
fields [1000] in index }
And my bulk insert looks like this:
with open('audit1.txt') as file:
for line in file:
columns = line.split(r'||')
dict['TimeStamp']=columns[0].strip('\'')
dict['BusinessTimeStamp']=columns[1].strip('\'')
dict['RuntimeMicroflowID']=columns[2].strip('\'')
dict['MicroflowID']=columns[3].strip('\'')
dict['UserId']=columns[4].strip('\'')
dict['ClientId']=columns[5].strip('\'')
dict['Userlocation']=columns[6].strip('\'')
dict['Transactionid']=columns[7].strip('\'')
dict['Catagorie']=columns[8].strip('\'')
dict['EventType']=columns[9].strip('\'')
dict['Operation']=columns[10].strip('\'')
dict['PrimaryData']=columns[11].strip('\'')
dict['SecondayData']=columns[12].strip('\'')
i=13
while i < len(columns):
tempdict['BFOLDVALUE'] = columns[i+1].strip('\'')
tempdict['BFNEWVALUE'] = columns[i+2].strip('\'')
if columns[i].strip('\'') is not None:
dict[columns[i].strip('\'')] = tempdict.copy()
i+=3
tempdict.clear()
#print(json.dumps(dict,indent = 4))
batch.append(dict)
if counter==BATCHSIZE:
try:
helpers.bulk(es, batch, index='audit-index', doc_type='audit')
insertedrecords+=counter
counter = 0
batch.clear()
print(insertedrecords," - Records Has Been inserted ")
except BulkIndexError:
print("Error Occured -- continuing")
print(json.dumps(dict,indent = 4))
print(BulkIndexError)
batch.clear()
break
counter+=1
dict.clear()
So, I am assuming I am trying to index this wrongly... is there a better way of indexing this kind of formats in elasticsearch? Note than I am using ELK version 7.5.
Here is the sample file I am parsing to elasticsearch:
2018.07.17/15:41:53.735||2018.07.17/15:41:53.735||'0164a8424fbbp84h%2139165'||'BT_TTB_CashDep_PRC'||'eskedarz'||'UXP'||'00001039'||'0164a842e519pJpA'||'Persistence'||''||'CREATE'||'DailyTxns'||'0164a842e4eapJnu'||'CurrentThread'||'WebContainer : 15'||''||'ParentThread'||'system'||''||'TCPWorkerThreadID'||'WebContainer : 15'||''||'f_POSTINGDT'||'2018-07-17'||''||'versionNum'||'0'||''||'f_TXNAMTDR'||'0'||''||'f_ACCOUNTID'||'013XXXXXXXXX0'||''||'f_VALUEDTTM'||'2018-07-17 15:41:53.0'||''||'f_POSTINGDTTM'||'2018-07-17 15:41:53.692'||''||'f_TXNCLBAL'||'25551.610000'||''||'f_TXNREF'||'0000103917071815410685326'||''||'f_PIEVENTTYPE'||'N'||''||'f_TXNAMT'||'5000.00'||''||'f_TRANSACTIONID'||'0164a842e4e9pJng'||''||'f_TYPE'||'N'||''||'f_USERID'||'xxxarz'||''||'f_SRNO'||'1'||''||'f_TXNBASEEQ'||'5000.00'||''||'f_TXNSRCBRANCH'||'0000X039'||''||'f_TXNCODE'||'T08'||''||'f_CHANNELID'||'BranchTeller'||''||'f_TXNAMTCR'||'5000.00'||''||'f_TXNNARRATION'||'SELF '||''||'f_ISACCRUALPENDING'||'false'||''||'f_TXNDTTM'||'2018-07-17 15:41:53.689'||''
if you carefully look at this part of the error message it would be clear.
Limit of total fields [1000] in index
1000 is the default limit of total fields in the Elasticsearch index as shown in their source code.
public static final Setting<Long> INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING =
Setting.longSetting("index.mapping.total_fields.limit", 1000L, 0, Property.Dynamic, Property.IndexScope);
Please note this is a dynamic setting, hence can be changed on a given index, by updating index setting
PUT test_index/_settings
{
"index.mapping.total_fields.limit": 1500. --> changed it to what is suitable for your index.
}
More info on this issue can be found here and here.
better way to handle such exploding index is to normalize as RDBMS that means store some of the key : value combinations in a nested structure
example
{"keyA":"ValueA","keyB":"ValueB","keyC":"ValueC"...} - record to
{"keyA":"ValueA","Keyvalue":{"keyB":"ValueB"
"keyC":"ValueC"}} - record
so searching would look like Keyvalue.Value == KeyB and KeyValue.Value = ValueB
i have update query problem in codeigniter.
$arrPartnerId = $partnerData['partner_id'];
print_r($partnerData['partner_id']);
if(is_array($arrPartnerId) > 0 ){
foreach( $arrPartnerId as $partnerId){
$this->db->set('partner_id', $partnerId );
$this->db->where('promotion_id', $promotionData['promotion_id'] );
$this->db->update('partner_promotion_relation');
}
}
my data is $aaPartnerId=([0]=>4,[1]=>5) and i have one id then how to update in database.
I think you confuse a where and set condition, you should rather have this :
$this->db->set('promotion_id', $promotionData['promotion_id']);
$this->db->where('partner_id', $partnerId);
$this->db->update('partner_promotion_relation');
It's just a hypothesis, because in your case you keep update 2 times the same line in your table, which is not logical.
If your array is like this,
$arrPartnerId = array(
0 => 4,
1 => 5
);
And
$promotionData['promotion_id'] = 123; //assumption
Then try this,
if(sizeof($arrPartnerId) > 0 )
{
foreach( $arrPartnerId as $partnerId)
{
$this->db->set('partner_id', $partnerId );
$this->db->where('promotion_id', $promotionData['promotion_id'] );
$this->db->update('partner_promotion_relation');
}
}
It will resolve the problem.
i have three tables
cases,clients,attendance
in cases
id start_date end_date client_id status
1 2012-12-30 2013-01-30 1 new starts
2 2012-12-31 2013-01-31 2 probation
in clients
id Name dob gender status
1 TOM 1987-01-30 M A
2 JERRY 1985-01-31 F D
in attendance
id client_id date status
1 1 2013-01-30 A
2 1 2013-01-31 P
i need result like this
case_id case_start_date case_end_date client_id Name
att_date atte_status
1 2012-12-30 2013-01-30 1 TOM
2013-01-30,2013-01-31 A,P
is this possible? i'm a self learner and i don't have good idea in join query please any body help me....
try this..
$this->db->select('ca.*,ci.Name,a.date,a.status');
$this->db->from('cases'.' ca');
$this->db->join('clients'.' ci','ca.client_id=ci.id','left');
$this->db->join('attendance'.' a','a.client_id=ci.id','left');
return $this->db->get();
go through the user guide if u want to read more about join and active records...
Here's a very simple example to get you started with any number of join common fun for all
Construcor Code
Construct $joins as array:
$joins = array(
array(
'table' => 'table2',
'condition' => 'table2.id = table1.id',
'jointype' => 'LEFT'
),
);
Example function handling joins as an array:
public function get_joins($table, $columns, $joins)
{
$this->db->select($columns)->from($table);
if (is_array($joins) && count($joins) > 0)
{
foreach($joins as $k => $v)
{
$this->db->join($v['table'], $v['condition'], $v['jointype']);
}
}
return $this->db->get()->result_array();
}