in reply to Re^2: Return value of Search::Elasticsearch search query
in thread Return value of Search::Elasticsearch search query

Please read the error message:

'reason' => 'failed to parse','type' => 'mapper_parsing_exception','ca +used_by' => {'reason' => 'Mixing up field types: class org.elasticsea +rch.index.mapper.core.StringFieldMapper$StringFieldType != class org. +elasticsearch.index.mapper.internal.IndexFieldMapper$IndexFieldType o +n field _index','type' => 'illegal_state_exception'}}}

What you submit does not match what Elasticsearch expects for the string field. So you should lean what Elasticsearch expects and then submit the appropriate data types.

You don't need to convert the Perl data structure to JSON yourself. The Search::Elasticsearch wrappers handle that for you.

Replies are listed 'Best First'.
Re^4: Return value of Search::Elasticsearch search query
by ravi45722 (Pilgrim) on Jul 10, 2016 at 02:55 UTC

    As per the error I am passing multi types(Hash & JSON). I am changing the ES query into JSON. Due to the error I am trying to pass the hash directly. This is my input doc

    { "sheets": { "sheet1": { "Sheet_Name": "Ex-Sheet", "formulating": [ { "0": { "colName": "Ex-Col1", "formula": "((column08=Submit | column10=Deliv +ered | column09=Something) & (column08=Delivered | column09=Something +))", "total": "false" }, "1": { "colName": "Ex-Col1", "formula": "((column08=Submit | column10=Deliv +ered | column09=Something) & (column08=Delivered | column09=Something +))", "total": "false" }, "2": { "colName": "Ex-Col1", "formula": "(column08=Submit & column10=Delive +red & column09=Something)", "total": "false" } } ] } } }

    From this input I am taking the formula field and changing into a ES query (hash). As Athanasius mentioned in the above reply I am replacing the formulae with my hash.

     $columns->{$one}{'formula'} = %main_hash; #main_hash contains ES query

    But its replacing as '1/8'. So I passed that as a address

     $columns->{$one}{'formula'} = \%main_hash;

    But now its working only for first element in the loop. For the second element its showing as

    [$VAR1->{'request'}{'body'}{'_source'}{'sheets'}{'sheet1'}{'forumle'}[ +0]{'1'}{'formula'}{'query'}{'constant_score'}{'filter'}{'bool'}{'shou +ld'}[0],$VAR1->{'request'}{'body'}{'_source'}{'sheets'}{'sheet1'}{'fo +rumle'}[0]{'1'}{'formula'}{'query'}{'constant_score'}{'filter'}{'bool +'}{'should'}[1],{'....

    How to replace my hash in the loop????

    if { ..... } else { my %main_hash = (); $main_hash{"query"}{"constant_score"}{"filter"} = @condition_array +[(int($condition)-1)]; my $json = encode_json \%main_hash; print Dumper \%main_hash; #printing very fine he +re $columns->{$one}{'formula'} = \%main_hash; #$columns is a address + in $doc print Dumper $doc; #Working only for firs +t element #exit; #print $json,$/; }

      You seem highly confused about data structures.</o>

      What do you mean by "working only for first element"? The first element of what? You never change $condition.

      Maybe you can manually create the data structure you want and then find out how to create that structure programmatically.

        I will explain more clearly now. In the input I have formula field with this type of data. I am changing it into equivalent ES query through perl and want to replace in the ES

        ((column08=Submit | column10=Delivered | column09=Something) & (column +08=Delivered | column09=Something))

        Need to replace with

        {'query' => {'constant_score' => {'filter' => {'bool' => {'should' => +[{'bool' => {'must' => [{'term' => {'column08' => 'Submit'}},{'term' +=> {'column10' => 'Delivered'}},{'term' => {'column09' => 'Something' +}}]}},{'bool' => {'must' => [{'term' => {'column08' => 'Delivered'}}, +{'term' => {'column09' => 'Something'}}]}}]}}}}}

        This is for one cell. In the input we can get multi sheets with multi cells in a single book (Excel). We have replace all cells in that.

        I am changing the input into the format what i need as in the output.

        { "sheets": { "sheet1": { "Sheet_Name": "Ex-Sheet", "forumle": [ { "0": { "colName": "Ex-Col1", "formula": "
        ((column08=Submit | column10=Delivered | column09=Something) & (column08=Delivered | column09=Something))
        ", "total": "false" }, "1": { "colName": "Ex-Col1", "formula": "
        ((column08=Submit | column10=Delivered | column09=Something) & (column08=Delivered | column09=Something))
        ", "total": "false" }, "2": { "colName": "Ex-Col1", "formula": "
        (column08=Submit & column10=Delivered & column09=Something)
        ", "total": "false" } } ] } } }
        My code

        getting the input into

        $doc

        from the ES

        Loop for getting all the conditions

        foreach my $sheet (keys %{ $doc->{'_source'}{'sheets'} }) { foreach my $columns (@{ $doc->{'_source'}{'sheets'}{$sheet}{'forum +le'} }) { foreach my $one (keys %{ $columns }) { $condition = $columns->{$one}{'formula'}; $return_value = function_to_change($condition); #H +ere I am changing my condition into required output $main_hash{"query"}{"constant_score"}{"filter"} = +{$return_value}; #Adding some more data for that $columns->{$one}{'formula'} = \%main_hash #Wha +t to replace that in the original doc } } }

        In the last line of my code I am replacing the existing field with a hash. But its working only for the first iteration of the loop. In the second iteration its showing like

        'bool' => { 'should' => [ $VAR1->{'_source'}{'sheets'}{'sheet1'}{' +forumle'}[0]{'1'}{'formula'}{'query'}{'constant_score'}{'filter'}{'bo +ol'}{'should'}[0], $VAR1->{'_source'}{'sheets'}{'sheet1'}{'f +orumle'}[0]{'1'}{'formula'}{'query'}{'constant_score'}{'filter'}{'boo +l'}{'should'}[1]]}

        instead of

        {"query":{"constant_score":{"filter":{"bool":{"should":[{"bool":{"must +":[{"term":{"column08":"Submit"}},{"term":{"column10":"Delivered"}},{ +"term":{"column09":"Something"}}]}},{"bool":{"must":[{"term":{"column +08":"Delivered"}},{"term":{"column09":"Something"}}]}},{"bool":{"must +":[{"term":{"column08":"Submit"}},{"term":{"column10":"Delivered"}},{ +"term":{"column09":"Something"}}]}},{"bool":{"must":[{"term":{"column +08":"Delivered"}},{"term":{"column09":"Something"}}]}}]}}}}}
        But When Dump the hash or converted into json & print Its looking fine. but When I assigned it to a hash It looking like that $var->. How do assign that