0
  • I need to have two settings
  • One is stopwords settings, second is synonym settings.
  • How to add different settings applied on one index

Below is stopwords setting which i need to apply on the index

settings_1 = {
  "settings": {
    "index": {
      "analysis": {
        "analyzer": {
          "my_stop_analyzer": {
            "type": "custom",
            "tokenizer": "standard",
            "filter": "my_fil"
          }
        },
        "filter": {
          "my_fil": {
            "type": "stop",
            "stopwords_path": "st.txt",
            "updateable": true
          }
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "description": {
        "type": "text",
        "analyzer": "standard",
        "search_analyzer": "my_stop_analyzer"
      }
    }
  }
}

Below is synonym setting which i need to apply on the index

settings_2 = {
  "settings": {
    "index": {
      "analysis": {
        "analyzer": {
          "my_analyzer": {
            "type": "custom",
            "tokenizer": "standard",
            "filter": [
              "my_filter"
            ]
          }
        },
        "filter": {
          "my_filter": {
            "type": "synonym",
            "synonyms_path": "sy.txt",
            "updateable": true
          }
        }
      }
    }
  },
  "mappings": {
    "properties": {
      "description": {
        "type": "text",
        "analyzer": "standard",
        "search_analyzer": "my_analyzer"
      }
    }
  }
}

Will the code work like below

  • es.indices.put_settings(index="gene", body=settings_1)

  • es.indices.put_settings(index="gene", body=settings_2)

sim
  • 524
  • 3
  • 14

1 Answers1

1

Although you can use the two different update setting like you mentioned but this is not a preferred way 1) it involves two network call to Elasticsearch 2) this can be combined in a single call and it will have less overhead at Elasticsearch to update the cluster state to all the nodes.

You can just combine both the settings and send single update setting request. you can first test this in Postman or kibana dev tools with JSON format.

As discussed in the comment, below is the complete setting and mapping part combining two settings(which defines two analyzer)

{
    "settings": {
        "index": {
            "analysis": {
                "analyzer": {
                    "my_stop_analyzer": {
                        "type": "custom",
                        "tokenizer": "standard",
                        "filter": "my_fil"
                    },
                    "my_analyzer": {
                        "type": "custom",
                        "tokenizer": "standard",
                        "filter": [
                            "my_filter"
                        ]
                    }
                },
                "filter": {
                    "my_fil": {
                        "type": "stop",
                        "stopwords_path": "analyzers/<your analyzer ID>",
                        "updateable": true
                    },
                    "my_filter": {
                        "type": "synonym",
                        "synonyms_path": "analyzers/F111111111",
                        "updateable": true
                    }
                }
            }
        }
    },
    "mappings": {
        "properties": {
            "description": {
                "type": "text",
                "analyzer": "standard",
                "search_analyzer": "my_stop_analyzer"
            }
        }
    }
}
Amit
  • 30,756
  • 6
  • 57
  • 88
  • Amit can you combine the setting and post the answer – sim Jun 29 '22 at 07:13
  • @sim, sure but I notice you are trying to apply two different `search_analyzer` to same field `description`, which is not possible – Amit Jun 29 '22 at 07:24
  • @sim if you can tell me on which field you want to apply `my_analyzer` , I can post complete setting with mapping, otherwise I am adding the setting part in my answer, Hope this helps – Amit Jun 29 '22 at 07:25
  • both analyzers are on "name" and "description" – sim Jun 29 '22 at 08:46
  • sorry for delay got into some work – sim Jun 29 '22 at 08:47
  • @sim, no worries, did you get a chance to look at my updated answer, you should be now able to construct complete mapping and change it according to your need – Amit Jun 29 '22 at 08:49
  • I got it, but there is missing the second mapping, also i need to put both settings to applied on "name" and "description" – sim Jun 29 '22 at 10:35
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/246019/discussion-between-amit-and-sim). – Amit Jun 29 '22 at 11:06