barseghyanartur / graphene-elastic

Graphene Elasticsearch/OpenSearch (DSL) integration
https://pypi.org/project/graphene-elastic/
71 stars 17 forks source link

Nested search backend #9

Open barseghyanartur opened 5 years ago

barseghyanartur commented 5 years ago

WIP in branch nested-search-backends.

seandavi commented 4 years ago

I have some nested objects in my models that I'd like to search on. I see the in progress label added recently. Do you have a sketch of what you are thinking here?

The rough by-hand approach that I had been working toward was to implement graphene types for nested objects, including search, etc. I hadn't gotten to the point of resolving the queries, though.

barseghyanartur commented 4 years ago

@seandavi:

Sure, I have a sketch. This whole project is designed after django-elasticsearch-dsl-drf. See the link for getting an impression what could you expect from NestedFilteringFilterBackend, as well as from additional (yet to come) functionality of the current SearchFilterBackend. And all of that still to be applied to Graphene.

Thus, still a little bit vague and unclear as I'm not yet certain on the implementation details or feature release dates.

seandavi commented 4 years ago

Thanks, @barseghyanartur. That helps quite a bit to know the functionality you are aiming to achieve. I'll try to digest that a bit.

lingfromSh commented 3 years ago

Hi, @barseghyanartur . I am trying to work on this feature. But i'm not certain how a nested search query should display in GraphQL.

Have you got any idea about this?

allPostDocuments(
    search: {
        tag: 'Python'            # a simple field
        comments: {            # a nested field
            query: 'Python',   # query on configured fields
            # tag: 'Python'     # search on a single field
        }
    }
){
    tag
    category
    comments{
        author
        tag
    }
}

or

allPostDocuments(
    search: {
        tag: 'Python'            # a simple field
    }
    nestedSearch: {
        comments: {            # a nested field
            query: 'Python',   # query on configured fields
            # tag: 'Python'
        }
    }
){
    tag
    category
    comments{
        author
        tag
    }
}
barseghyanartur commented 3 years ago

@lingfromSh:

The first approach looks cleaner, although might be a little bit more difficult to implement, but I think we should aim for that (the first option). However, if it does not work out (or hard to implement in a generic way), we should fall back to the second option (which would be easy-peasy).

barseghyanartur commented 3 years ago

P. S. I've merged your another PR into the master, but there are some issues with tests due to merging. I'm solving it later on today. I think tomorrow we'll have master all clean and working so that you could branch from that.

lingfromSh commented 3 years ago

okay.

barseghyanartur commented 3 years ago

Master is updated. Changes released as 0.7.

lingfromSh commented 3 years ago

Thanks for reminding.

And I see the current config format of search_fields like below. search/common.py

search_fields = {
    'title': {'boost': 4, 'field': 'title.raw'},
    'content': {'boost': 2},
    'category': None,
}

It's inconvenient to set (when i have many fields but only one field need boost). Can i change them into this type?

# Type 3
search_fields = [
    {
        'field': 'title', 
        'boost': 2
    },
    'content',
    'category',
    'description',
    'summary'
]

Although we may need a extra filter to find related option instead of search_fields.get(field) when in prepare_search_fields, i feel it worths.

Suggestions are welcomed.

barseghyanartur commented 3 years ago

@lingfromSh:

Let's leave the current config format intact. It's just the way it is.

lingfromSh commented 3 years ago

Okay

MamtaPrasad commented 1 year ago

What is the sample query for Nested Search ? I am using version 0.8 of this library and have configured search_nested_fields .But when I query the nested data is coming as null. Please advise. My schema is as below : class address(InnerDoc): city= Text(fields={"raw": Keyword()}) zip= Text(fields={"raw": Keyword()})

class person(Document): name=Text(fields={"raw": Keyword()}) title=Text(fields={"raw": Keyword()}) address=Nested(address)

query is " query { person(search:{name:{ value:"John" } }) { edges {node {name title address{city}}}}} "

getting this error : search_phase_execution_exception', 'failed to create query: [nested] failed to find nested object under path [address]