Elasticsearch 1.7 - how to find some data with a lot "or/end" filters


(Damian Giebas) #1

Hi.

I have a little problem with searching. In my ES I have document with the structure shown below. I need do some like this

SELECT * ... WHERE synchronization_report.id IN (1, 2, 47, 57) AND synchronization_report_data_sets IN (user_and_passwords_server3) AND synchronization_report_data_area.configuration_id IN (oldpassword, users)

I created some simple query to search using synchronization_report.id but I don't know how use another filters.

{
    "query": {
        "filtered": {
            "filter": {
                "or": [
                    {
                        "term": {
                            "synchronization_report.id": 47
                        }
                    }
                ]
            }
        }
    }
}

Document structure

{
    "_id": "374",
    "_index": "development_synchronization_report_job_searches",
    "_score": 1.0,
    "_source": {
        "created_at": "2015-09-23T10:43:51.447Z",
        "end_time": "2015-07-22T11:58:03.000Z",
        "error": null,
        "id": 374,
        "job_id": 1,
        "job_type": "select",
        "name": "queryElement",
        "start_time": "2015-07-22T11:58:03.000Z",
        "synchronization_report": {
            "created_at": "2015-09-23T10:43:51.412Z",
            "id": 47,
            "mode": "PUSH",
            "server": "LinuxServer",
            "server_agent_number": 2,
            "source_server": null,
            "source_server_agent_number": null,
            "source_sync_id": "5ce413f5-b99c-4d69-b5d9-dd6236b346b8",
            "synch_agent_id": 1,
            "synch_completed_time": "2015-07-22T11:58:03.000Z",
            "updated_at": "2015-09-23T10:43:51.412Z"
        },
        "synchronization_report_data_area": {
            "configuration_id": "oldpasswords",
            "created_at": "2015-09-23T10:43:51.438Z",
            "error_text": null,
            "error_type": null,
            "id": 94,
            "records_files_processed": 7,
            "sql": null,
            "status": "exported",
            "synchronization_report_data_set_id": 47,
            "updated_at": "2015-09-23T10:43:51.481Z"
        },
        "synchronization_report_data_area_id": 94,
        "synchronization_report_data_set": {
            "configuration_id": "users_and_passwords_server3",
            "created_at": "2015-09-23T10:43:51.415Z",
            "id": 47,
            "synch_time": "2015-07-22T11:58:03.000Z",
            "synchronization_report_id": 47,
            "updated_at": "2015-09-23T10:43:51.415Z"
        },
        "updated_at": "2015-09-23T10:43:51.447Z"
    },
    "_type": "search"
}

Any help will be appreciated.
Best regards.


(Camilo Sierra) #2

hello @Draqun ! use or is not the best option, tried to use bitset => https://www.elastic.co/blog/all-about-elasticsearch-filter-bitsets

i let you one example :

    {
    "query": {
        "filtered": {
            "filter": {
                "bool": {
                    "must": [
 {
                            "term": {
                                "synchronization_report_data_sets":  user_and_passwords_server3
                            }
                        },
                        {
                            "terms": {
                                "job_id": [
                                    7,
                                    1
                                ]
                            }
                        },
                        {
                            "terms": {
                                "synchronization_report.id": [1, 2, 47, 57]
                            }
                        },
 {
                            "terms": {
                                "synchronization_report_data_area.configuration_id": ["users","oldpassword"]
                            }
                        }
                    ]
                }
            }
        }
        }
    }

(Damian Giebas) #3

I'll read this. Thanks for quick answer.

Best regards.


(system) #5