Skip to content

Is it possible to index attributes conditionally ? #995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Emilie-thp opened this issue Jul 7, 2021 · 1 comment
Closed

Is it possible to index attributes conditionally ? #995

Emilie-thp opened this issue Jul 7, 2021 · 1 comment
Labels

Comments

@Emilie-thp
Copy link

Emilie-thp commented Jul 7, 2021

I'm new to ElasticSearch so I don't know if my question is relevant.
Given the following mappings, is it possible to index an attribute in a nested field only if a condition is matched..?

    settings do
      mappings dynamic: 'false' do
        indexes	:id, type: :keyword
        indexes :areas, type: 'nested' do
          indexes :id, type: :keyword
          indexes :area_type, type: :keyword
          indexes :zone, type: :geo_shape // => NEED A CONDITION HERE : index zone geo_shape only if the area has a specific area_type 
        end
      end
    end

My zone method for the geo_shape definition, in Area model looks like this :

  def zone
    { type: 'polygon',
      coordinates: [get_coordinates] }
  end

but my problem is that all areas do NOT need a geo_shape indexing. I want to index geo_shape only for area with a specific area_type.
If indexing is absolutely necessary for all attributes, I was thinking of indexing an empty geo_shape instead of a polygon (but I don't manage to do this).

Your help would be much appreciated on this point,

@stale
Copy link

stale bot commented Jan 9, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jan 9, 2022
@stale stale bot closed this as completed Apr 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant